fix: BaseModel/Patcher record desync after save() causes silent sette…#1567
Merged
fix: BaseModel/Patcher record desync after save() causes silent sette…#1567
Conversation
Kanishkavijay39
approved these changes
Apr 29, 2026
solaris007
approved these changes
Apr 29, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This PR will trigger a patch release when merged. |
solaris007
pushed a commit
that referenced
this pull request
Apr 29, 2026
## [@adobe/spacecat-shared-data-access-v3.55.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.55.0...@adobe/spacecat-shared-data-access-v3.55.1) (2026-04-29) ### Bug Fixes * BaseModel/Patcher record desync after save() causes silent sette… ([#1567](#1567)) ([c9c782d](c9c782d))
Member
|
🎉 This PR is included in version @adobe/spacecat-shared-data-access-v3.55.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Summary
Fixes a bug in
@adobe/spacecat-shared-data-accesswhere setter writes are not visible via getters on the same model instance after a priorsave(). Setters appear to silently no-op until the model is reloaded.Root cause
BaseModelandPatcherare constructed sharing a singlerecordobject reference (base.model.js:64,72). Onpatcher.save(),collection.applyUpdateWatchers(this.record, updates)returns a shallow clone (base.collection.js:255—const nextRecord = { ...record }). The patcher then reassignsthis.record = watched.record(patcher.js:183), but the model'sthis.recordis never updated.After that point:
patcher.record(the new clone)model.record(the stale original)The
_saveManypath explicitly syncs the model (base.collection.js:999—preparedItem.model.record = preparedItem.record). The singlesave()path was missing the equivalent sync.Reproduction
Fix
packages/spacecat-shared-data-access/src/util/patcher.js:183— replacethis.record = watched.recordwithObject.assign(this.record, watched.record). This preserves the shared object reference betweenPatcher.recordandBaseModel.record, so post-save setters and getters stay in sync. No public API change.Why it wasn't caught
test/unit/util/patcher.test.jsstubbedapplyUpdateWatchersand asserted onlyupdateByKeys.calledOnce— never constructed a realBaseModelto verify post-save getter reads.test/unit/models/base/base.model.test.jsstubspatcher.saveentirely, so the real reassignment never runs.set → save → set → getsequence.Test plan
test/unit/util/patcher.test.js:preserves the record reference after a collection-strategy savereflects subsequent patches on the same record after a savetest/it/site/site.test.js:reflects setter writes via getters after a prior save on the same instancenpm run lint -w packages/spacecat-shared-data-accessnpm test -w packages/spacecat-shared-data-access(full unit suite, CI)npm run test:it -w packages/spacecat-shared-data-access(integration suite, CI/local Docker)Related Issues