{"record":{"id":"a3fbc2f165e3c35f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-call-create-block-partition-for-chain","errorCode":null,"errorMessage":"Failed to call create_block_partition for chain {}: {e}","messagePattern":"Failed to call create_block_partition for chain (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":378,"sourceCode":"        .execute(&self.pool)\n        .await\n        .map(|_| ())\n        .map_err(|e| anyhow::anyhow!(\"Failed to seed chain table: {e}\"))\n    }\n\n    /// Creates a table partition for the block table specific to the given chain\n    /// by calling the existing PostgreSQL function `create_block_partition`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    pub async fn create_block_partition(&self, chain: &Chain) -> anyhow::Result<String> {\n        let result: (String,) = sqlx::query_as(\"SELECT create_block_partition($1)\")\n            .bind(chain.chain_id as i32)\n            .fetch_one(&self.pool)\n            .await\n            .map_err(|e| {\n                anyhow::anyhow!(\n                    \"Failed to call create_block_partition for chain {}: {e}\",\n                    chain.chain_id\n                )\n            })?;\n\n        Ok(result.0)\n    }\n\n    /// Creates a table partition for the token table specific to the given chain\n    /// by calling the existing PostgreSQL function `create_token_partition`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    pub async fn create_token_partition(&self, chain: &Chain) -> anyhow::Result<String> {\n        let result: (String,) = sqlx::query_as(\"SELECT create_token_partition($1)\")\n            .bind(chain.chain_id as i32)\n            .fetch_one(&self.pool)","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L360-L396","documentation":"create_block_partition calls the PostgreSQL function create_block_partition($1) for a chain and this error wraps any sqlx failure of that SELECT. The partition function itself may also fail server-side (e.g. partition already exists in a conflicting way), which surfaces through sqlx as a database error. The chain_id is included in the message to identify the failing chain.","triggerScenarios":"Calling CacheDatabase::create_block_partition during cache initialization and either the query fails (connection, function missing) or the server-side function raises an error for that chain_id.","commonSituations":"Migrations not applied so create_block_partition() function doesn't exist; DB user lacks EXECUTE on the function; calling it for a chain whose partition state conflicts.","solutions":["Check the wrapped {e} — 'function create_block_partition(...) does not exist' means migrations were not run","Apply the latest schema migrations before initializing the cache","Grant EXECUTE on the partition functions to the application DB role","Verify the parent block table and partition scheme exist for the chain_id"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// ensure the partition function exists before calling it\nlet exists: (bool,) = sqlx::query_as(\n    \"SELECT EXISTS (SELECT 1 FROM pg_proc WHERE proname='create_block_partition')\"\n).fetch_one(&pool).await?;\nif !exists.0 {\n    return Err(anyhow::anyhow!(\"create_block_partition missing; run migrations first\"));\n}","typeGuard":null,"tryCatchPattern":"db.create_block_partition(&chain).await.map_err(|e| {\n    if e.to_string().contains(\"does not exist\") {\n        anyhow::anyhow!(\"schema not migrated: {e:#}\")\n    } else {\n        anyhow::anyhow!(\"partition creation failed for chain {}: {e:#}\", chain.chain_id)\n    }\n})?;","preventionTips":["Apply all cache-schema migrations before constructing CacheDatabase","Grant EXECUTE on partition helper functions to the application DB role","Run partition creation idempotently at startup for every configured chain","Verify chain_id fits in i32 before binding it as a query parameter"],"tags":["database","postgres","partitioning","sqlx"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}