{"record":{"id":"ca41fde86b26b3f1","repo":"clockworklabs/SpacetimeDB","slug":"database-addr-not-yet-initialized","errorCode":null,"errorMessage":"database `{addr}` not yet initialized","messagePattern":"database `(.+?)` not yet initialized","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/host/host_controller.rs","lineNumber":1145,"sourceCode":"\n/// Update a module.\n///\n/// If the `db` is not initialized yet (i.e. its program hash is `None`),\n/// return an error.\n///\n/// Otherwise publish the complete environment with the module, including when\n/// its program hash is unchanged.\nasync fn update_module(\n    db: &RelationalDB,\n    module: &ModuleHost,\n    program: Program,\n    old_module_info: Arc<ModuleInfo>,\n    policy: MigrationPolicy,\n    environment: std::collections::BTreeMap<String, String>,\n) -> anyhow::Result<UpdateDatabaseResult> {\n    let addr = db.database_identity();\n    let Some(stored) = stored_program_hash(db)? else {\n        bail!(\"database `{addr}` not yet initialized\");\n    };\n    info!(\"publishing `{}` from {} to {}\", addr, stored, program.hash);\n    // Even an unchanged program publishes a complete replacement environment.\n    module\n        .update_database_with_environment(program, old_module_info, policy, environment)\n        .await\n}\n\n/// Encapsulates a database, associated module, and auxiliary state.\nstruct Host {\n    /// The [`ModuleHost`], providing the callable reducer API.\n    ///\n    /// Modules may be updated via [`Host::update_module`].\n    /// The module is wrapped in a [`watch::Sender`] to allow for \"hot swapping\":\n    /// clients may subscribe to the channel, so they get the most recent\n    /// [`ModuleHost`] version or an error if the [`Host`] was dropped.\n    module: watch::Sender<ModuleHost>,\n    /// Pointer to the `module`'s [`ReplicaContext`].","sourceCodeStart":1127,"sourceCodeEnd":1163,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/core/src/host/host_controller.rs#L1127-L1163","documentation":"update_module runs module.update_database only when the database already stores a program hash; stored_program_hash(db) returning None means this database identity never had a program published. The host refuses to 'update' an uninitialized database instead of invoking the module. It indicates an update was requested before the initial publish completed, or against the wrong database.","triggerScenarios":"The publish pipeline routes a module update to a freshly created database before the initial program publish commits; update_module is called on a database recreated after data loss; the wrong DatabaseIdentity is passed to the update path.","commonSituations":"Race between database creation and publish in CI; a crashed first publish leaving no stored program; a misconfigured address variable pointing updates at an empty database.","solutions":["Publish (initialize) the module on the database first, then retry the update.","Verify the DatabaseIdentity/address used for the update matches the intended database.","Inspect the stored program (stored_program_hash / describe APIs) to confirm initialization before updating.","If the first publish crashed, re-run the full publish rather than the update path."],"exampleFix":"// before\nupdate_module(&db, &module, program, old_info, policy).await?; // database `{addr}` not yet initialized\n\n// after\nif stored_program_hash(&db)?.is_none() {\n    module.publish_database(/* ... */).await?; // initial publish initializes the program\n} else {\n    update_module(&db, &module, program, old_info, policy).await?;\n}","handlingStrategy":"validation","validationCode":"if stored_program_hash(&db)?.is_none() {\n    // not initialized: run the publish path, not the update path\n    return publish_database(&db, program).await;\n}","typeGuard":null,"tryCatchPattern":"Catch the error in update orchestration and fall back to the publish/initialize flow for that database identity.","preventionTips":["Sequence tooling so publish always precedes update for a new database address.","Persist the database address from creation and reuse it; never guess addresses.","Treat 'not yet initialized' as control flow, not corruption."],"tags":["database","initialization","publish","update","program-hash"],"backgroundTag":"database-not-initialized","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}