fix: backfill schemaDefined on replicas missing the flag#503
Conversation
| @@ -1080,6 +1082,7 @@ export function table<TableResourceType>(tableDefinition: TableDefinition): Tabl | |||
| if (sealed !== undefined) updatedPrimaryAttribute.sealed = sealed; | |||
| if (replicate !== undefined) updatedPrimaryAttribute.replicate = replicate; | |||
| if (attribute.type) updatedPrimaryAttribute.type = attribute.type; | |||
| if (needsSchemaDefinedBackfill) updatedPrimaryAttribute.schemaDefined = schemaDefined; | |||
There was a problem hiding this comment.
Missing test for the backfill path
What: The needsSchemaDefinedBackfill check introduces a two-leg runtime-shape branch (schemaDefined === undefined vs present) with no test covering the backfill leg. The normal leg (descriptor already has schemaDefined) is exercised by existing tests; the new leg is not.
Why it matters: A regression here — e.g. the write silently no-ops or persists the wrong value — would leave replica tables still missing the flag after a restart. The fix looks correct today, but without a test this is invisible to CI.
Suggested fix: Add a unit test (alongside the existing unitTests/resources/databases.test.js suite) that:
- Opens or creates a table (so
schemaDefined=trueis written to the descriptor). - Manually overwrites the primary-key entry in
attributesDbiwith a copy that omitsschemaDefined(simulating an old replica). - Calls
table()again with the same definition. - Asserts that
Table.schemaDefined === trueand that the stored descriptor now containsschemaDefined: true.
1. Missing test for the
|
cb1kenobi
left a comment
There was a problem hiding this comment.
I don't know much about this, but makes sense. It would be nice if it was easy to add a test that demonstrates this fixes things.
|
What is the situation where this can occur? I thought line 907 in databases.ts consistently set this flag. |
No description provided.