nautechsystems/nautilus_trader · error

Database is not initialized

Error message

Database is not initialized

What it means

`needs_bootstrap_before_target` inspects the latest stored pool snapshot from the cache's backing database to decide whether a bootstrap pass is required. If `cache.database` is `None` (no persistent database configured on the data client), the check cannot run and this error is raised.

Source

Thrown at crates/cli/src/blockchain/analyze.rs:443

        .iter()
        .copied()
        .filter(|&block| block <= to_block)
        .collect();
    checkpoints.sort_unstable();
    checkpoints.dedup();
    checkpoints
}

async fn needs_bootstrap_before_target(
    data_client: &BlockchainDataClientCore,
    pool_identifier: &PoolIdentifier,
    to_block: u64,
) -> anyhow::Result<bool> {
    let database = data_client
        .cache
        .database
        .as_ref()
        .ok_or_else(|| anyhow::anyhow!("Database is not initialized"))?;
    let snapshot = database
        .load_latest_pool_snapshot(
            data_client.chain.chain_id,
            pool_identifier,
            Some(to_block),
            true,
        )
        .await?;

    let Some(snapshot) = snapshot else {
        return Ok(true);
    };
    let snapshot_needs_bootstrap = data_client
        .cache
        .get_pool(pool_identifier)
        .is_some_and(|pool| is_empty_creation_snapshot(&snapshot, pool.creation_block));

    Ok(snapshot_needs_bootstrap)

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Configure a database on the data client (connection string/env config) so `cache.database` is `Some`.
  2. Check the CLI's chain/database configuration files for missing connection settings.
  3. Verify how the data client is built in the analyze command path and that the DB-backed constructor is used.
  4. Inspect inner code to see whether the bootstrap check can be skipped legitimately for non-persistent runs.

Example fix

// before: cache built without db
let cache = Cache::new(None);
// after
let cache = Cache::new(Some(database.clone()));
Defensive patterns

Strategy: validation

Validate before calling

if data_client.cache.database.is_none() {
    anyhow::bail!("configure a database for pool analysis before running");
}

Prevention

When it happens

Trigger: Running pool analysis against a data client whose cache was constructed without a database (e.g. missing connection string/config, or an in-memory-only client), when the code reaches the bootstrap decision point.

Common situations: Forgetting to configure the nautilus PostgreSQL/cache database in the CLI config; running analysis in an environment where the DB-backed client factory was bypassed; a refactor/upgrade dropping the database from client construction.

Related errors


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