{"record":{"id":"274f9d316478b8ef","repo":"nautechsystems/nautilus_trader","slug":"execution-payload-migration-found-invalid-invali","errorCode":null,"errorMessage":"Execution payload migration found {invalid} invalid representation(s)","messagePattern":"Execution payload migration found (.+?) invalid representation\\(s\\)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5026,"sourceCode":"\n    async fn complete_execution_payload_migration(\n        &self,\n        transaction: &mut Transaction<'_, Postgres>,\n        keys: &PayloadKeySet,\n    ) -> anyhow::Result<()> {\n        sqlx::query(\"LOCK TABLE execution_transaction_hash IN SHARE ROW EXCLUSIVE MODE\")\n            .execute(&mut **transaction)\n            .await\n            .context(\"failed to lock execution payload migration completion\")?;\n        let invalid = sqlx::query_scalar::<_, i64>(\n            \"SELECT COUNT(*) FROM execution_transaction_hash \\\n             WHERE (payload_expected AND (raw_transaction IS NOT NULL OR sealed_transaction IS NULL)) \\\n                OR (NOT payload_expected AND (raw_transaction IS NOT NULL OR sealed_transaction IS NOT NULL))\",\n        )\n        .fetch_one(&mut **transaction)\n        .await\n        .context(\"failed to verify migrated execution payload representations\")?;\n        anyhow::ensure!(\n            invalid == 0,\n            \"Execution payload migration found {invalid} invalid representation(s)\"\n        );\n        validate_execution_payload_key_inventory(transaction, keys).await?;\n\n        for statement in [\n            \"ALTER TABLE execution_transaction_hash \\\n             DROP CONSTRAINT IF EXISTS execution_transaction_payload_protected_check\",\n            \"ALTER TABLE execution_transaction_hash \\\n             ADD CONSTRAINT execution_transaction_payload_protected_check CHECK ( \\\n                 (payload_expected AND raw_transaction IS NULL AND sealed_transaction IS NOT NULL) \\\n                 OR (NOT payload_expected AND raw_transaction IS NULL AND sealed_transaction IS NULL) \\\n             )\",\n        ] {\n            sqlx::query(statement)\n                .execute(&mut **transaction)\n                .await\n                .context(\"failed to install protected execution payload constraint\")?;","sourceCodeStart":5008,"sourceCodeEnd":5044,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5008-L5044","documentation":"After migrating execution payload representations, this check counts rows whose stored representation (raw_transaction / sealed_transaction presence) contradicts the expected payload state, and aborts the migration if any are invalid. It guards against the migration producing an inconsistent mix of legacy and protected representations.","triggerScenarios":"Running the execution payload migration when rows exist where payload_expected is true but sealed_transaction is NULL or raw_transaction leaked in, or payload_expected is false but transaction columns are populated.","commonSituations":"Interrupted earlier migration leaving half-migrated rows; manual edits to execution payload tables; schema changes that bypassed the migration's invariants.","solutions":["Identify the offending rows with the migration's verification query and fix them manually to match payload_expected","Restore the tables from a backup taken before the failed migration","Re-run migration from a clean pre-migration state","Check application code that writes raw_transaction/sealed_transaction directly, bypassing the migration invariants"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let invalid: i64 = sqlx::query_scalar(\n    \"SELECT COUNT(*) FROM execution_payload_state s JOIN execution_payload p ON ... WHERE (s.payload_expected AND (p.raw_transaction IS NOT NULL OR p.sealed_transaction IS NULL)) OR (NOT s.payload_expected AND (p.raw_transaction IS NOT NULL OR p.sealed_transaction IS NOT NULL))\"\n).fetch_one(&mut conn).await?;\nassert_eq!(invalid, 0, \"fix invalid payload representations before migrating\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Back up tables before running the migration","Never hand-edit execution payload columns","Verify invariants after any restore from backup","Keep all node instances on the same version"],"tags":["database","migration","data-integrity"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}