Repository navigation
fix(memory-storage): store JSON snapshots in DatasetClient.pushData() - #3831
Merged
Merged
Conversation
Store JSON.parse(JSON.stringify(entry)) instead of the raw object reference so that each push produces an independent deep copy. This makes MemoryStorageClient consistent with FileSystemStorageClient, which already stores independent snapshots. Fixes apify#3812 Co-authored-by: atlarix-agent <agent@atlarix.dev>
This comment was marked as spam.
This comment was marked as spam.
barjin
approved these changes
Jul 9, 2026
barjin
pushed a commit
that referenced
this pull request
Jul 20, 2026
…)` (#3831) Serializes the passed data in `pushData` calls before storing it.
B4nan
pushed a commit
that referenced
this pull request
Aug 12, 2026
…)` (#3831) Serializes the passed data in `pushData` calls before storing it.
B4nan
pushed a commit
that referenced
this pull request
Aug 18, 2026
…)` (#3831) Serializes the passed data in `pushData` calls before storing it.
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.
PR Description
What was the issue
MemoryStorageClient'sDatasetClient.pushData()stored the raw object reference into its internalMaprather than taking an independent deep copy. Later mutations to the original object were reflected in every stored entry — pushing the same mutable object multiple times (mutating between pushes) resulted in all items holding the same final value. This was inconsistent withFileSystemStorageClient, which serializes to disk on each push and therefore stores independent snapshots.Where was the issue
packages/core/src/memory-storage/resource-clients/dataset.ts:127This line stored the direct reference — no copy, no serialization.
How was it fixed
Store
JSON.parse(JSON.stringify(entry))instead of the raw object reference so that each push produces an independent deep copy. This makesMemoryStorageClientconsistent withFileSystemStorageClient, which already stores independent snapshots.Why this method over alternatives
JSON.parse(JSON.stringify())is the canonical JavaScript deep-clone for JSON-serializable data — no dependencies, no overheadDatasetfrontend already enforces JSON serializability viaassertJsonSerializablebefore data reaches the client, so this clone is guaranteed to succeed for every valid itemstructuredClone()handles types (Date,Map,ArrayBuffer, etc.) that dataset items can never contain (the validation gate rejects them), making it unnecessary overheadHow to test locally
pnpm test -- test/core/storages/dataset.test.tsThe added regression test
"stores independent snapshots, not object references"pushes a mutable object three times with mutations between pushes, then asserts items have distinct values and are not the same reference.Reproduction from the issue:
Fixes #3812