nautechsystems/nautilus_trader · error · anyhow::Error

Unknown data type: {type_name}

Error message

Unknown data type: {type_name}

What it means

decode_batch_to_data dispatches on the record's type name. When the type is not a built-in type decodable natively and the 'python' feature is disabled, there is no registered decoder for the type, so decoding fails with 'Unknown data type'. Custom data decoding via Python is only available with the python feature enabled.

Source

Thrown at crates/persistence/src/backend/custom.rs:218

        "MarkPriceUpdate" | "mark_price_updates" => {
            Ok(MarkPriceUpdate::decode_data_batch(metadata, batch)?)
        }
        "IndexPriceUpdate" | "index_price_updates" => {
            Ok(IndexPriceUpdate::decode_data_batch(metadata, batch)?)
        }
        "OptionGreeks" | "option_greeks" => Ok(OptionGreeks::decode_data_batch(metadata, batch)?),
        "InstrumentClose" | "instrument_closes" => {
            Ok(InstrumentClose::decode_data_batch(metadata, batch)?)
        }
        _ => {
            if allow_custom_fallback {
                #[cfg(feature = "python")]
                {
                    return Ok(CustomDataDecoder::decode_data_batch(metadata, batch)?);
                }
                #[cfg(not(feature = "python"))]
                {
                    anyhow::bail!("Unknown data type: {type_name}");
                }
            }
            anyhow::bail!(
                "Unknown data type: {type_name}; custom decode only allowed in custom data context"
            )
        }
    }
}

/// Decodes multiple `RecordBatches` (e.g. from custom data files) into a single `Vec<Data>`.
/// Optionally replaces `ts_init` column with `ts_event` before decoding each batch.
///
/// # Errors
///
/// Returns an error if any batch fails to decode.
pub fn decode_custom_batches_to_data(
    batches: Vec<RecordBatch>,
    use_ts_event_for_ts_init: bool,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Rebuild with the 'python' feature enabled (cargo build --features python) so Python-backed decoders are available.
  2. Filter out or skip unknown data types when querying the catalog.
  3. Verify the type_name matches a type registered/known in this build; align versions between writer and reader.
  4. Convert the data with a Python-enabled build first, or re-export the data in a built-in supported type.

Example fix

// before — pure Rust build reading Python-written custom data
let data = catalog.query(...)?; // bails: Unknown data type: custom/MySignal
// after — enable the feature in Cargo.toml
[dependencies.nautilus-persistence]
features = ["python"]
Defensive patterns

Strategy: fallback

Validate before calling

// build-time guard in Cargo.toml
// [features] ensure 'python' is enabled when the catalog may contain Python custom data
fn can_decode(type_name: &str, python_enabled: bool) -> bool {
    is_builtin_type(type_name) || (python_enabled && is_registered_custom_type(type_name))
}

Try / catch

match decode_custom_batches_to_data(batches) {
    Err(e) if e.to_string().contains("Unknown data type") => {
        // skip this batch/type or switch to a python-feature-enabled build
    }
    other => other?,
}

Prevention

When it happens

Trigger: Reading a catalog containing custom/unknown data types from a Rust build compiled without the 'python' feature (e.g. a pure-Rust binary reading data written from Python-defined custom types), or a genuinely misspelled/unknown type name.

Common situations: A Rust-only deployment consuming a catalog produced by nautilus_trader Python with custom data classes; mixing builds with different feature flags; reading catalogs from newer versions with types unknown to the reader.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/889acfe3c40633ff. Report an issue: GitHub.