Fix _attachments not forwarded across chained migration strategies#8399
Open
Fix _attachments not forwarded across chained migration strategies#8399
Conversation
When a migration strategy returned a new object without forwarding the
`_attachments` field, subsequent strategies received the document with
`_attachments` as `undefined`. This violated the public
`WithAttachments<DocData>` contract and prevented strategies from reading
or mutating attachment metadata as described in the docs example.
`migrateDocumentData()` now tracks the last-known `_attachments` value
across strategy invocations and re-attaches it before the next strategy
runs, while still honoring explicit rewrites (e.g. `_attachments = {}`).
https://claude.ai/code/session_01UiLzK67sLGyehJis5YfBYb
Contributor
✅ Verify Test Reproduction: Tests FAILED without the fix (expected)This confirms the changed tests correctly reproduce the bug that the source changes fix. This workflow runs the changed tests without the source fix to verify they reproduce the bug. Show output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains:
Describe the problem you have without this PR
When using multiple chained migration strategies in schema migrations, if an intermediate strategy returns a new object without forwarding the
_attachmentsfield, subsequent strategies would receive the document with_attachmentsasundefined. This breaks the documented public API contract where strategies receive documents typed asWithAttachments<DocData>and can mutateoldDoc._attachments.Solution
Modified the migration pipeline in
migrateDocumentData()to track attachments across chained strategies. Each strategy now receives the document with_attachmentsproperly attached, even when a previous strategy returned a fresh object without forwarding it. If a strategy explicitly sets_attachments, that value becomes the new baseline for subsequent strategies.The fix moves attachment restoration from the final step to each intermediate step in the promise chain, ensuring every strategy sees the correct document shape.
Changes
currentAttachmentsacross strategy invocations and restore them after each strategy executes (unless the strategy explicitly provided new attachments)_attachmentsare preserved when strategy 1 returns a new object without forwarding attachments, and strategy 2 can still access and verify themTest Plan
Added comprehensive regression test that:
_attachments_attachmentsand can detect the attachmentExisting tests continue to pass.
https://claude.ai/code/session_01UiLzK67sLGyehJis5YfBYb