Skip to content

fix: Fix the serialization issue of nested attribute cache#2943

Open
wells1013 wants to merge 1 commit intoparse-community:alphafrom
wells1013:feature/tag-8.3.0
Open

fix: Fix the serialization issue of nested attribute cache#2943
wells1013 wants to merge 1 commit intoparse-community:alphafrom
wells1013:feature/tag-8.3.0

Conversation

@wells1013
Copy link

@wells1013 wells1013 commented Mar 5, 2026

Pull Request
Report security issues confidentially.
Any contribution is under this license.
Link this pull request to an issue.

Approach
This PR fixes a serialization issue in the nested attribute cache handling within the commitServerChanges function in ObjectStateMutations.ts. The issue was that when dealing with nested attributes (using dot notation like "address.street"), the caching mechanism was not properly handling the serialization and storage of these nested values.

Key Changes:
Fixed nested attribute cache key handling: When processing nested attributes (e.g., "address.street"), the code now correctly extracts the root key ("address") for caching purposes instead of using the full nested path.

Improved cache value retrieval: For nested attributes, the code now retrieves the entire parent object from server data rather than just the leaf value, ensuring proper serialization of the complete nested structure.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed caching behavior for nested attributes using dot notation paths. Cache keys and values are now properly derived from the nested structure itself, improving data storage efficiency and retrieval performance during server-client synchronization operations.

@parse-github-assistant
Copy link

🚀 Thanks for opening this pull request!

@parseplatformorg
Copy link
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

The commitServerChanges method in ObjectStateMutations.ts now derives separate cache key and value for dot-notation attributes. For nested paths, the cache key becomes the first path segment and the cached value is sourced from the corresponding serverData entry, changing where and how nested attributes are cached.

Changes

Cohort / File(s) Summary
Cache Handling for Dot-Path Attributes
src/ObjectStateMutations.ts
Modified commitServerChanges to compute derived cacheVal and cacheKey for caching. Dot-notation attributes now use the first path segment as cache key and extract cached value from serverData[firstKey] instead of using the full attribute name.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides approach details and key changes but is missing the required 'Issue' section with a link to the GitHub issue being closed. Add the 'Issue' section with 'Closes: #XXXX' to link this PR to the related GitHub issue as required by the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix for nested attribute cache serialization, directly matching the main change in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/ObjectStateMutations.ts (1)

229-256: The caching logic fix is correct; minor style nits.

The fix correctly addresses the cache key mismatch: _getDirtyObjectAttributes in ParseObject.ts looks up objectCache[attr] using top-level attribute keys (e.g., "address"), so storing under the root key with the full parent object is the right approach.

A few minor style issues:

  1. Lines 233-234 and 254-256 are missing semicolons, but the rest of the file consistently uses them.
  2. The _rest variable is unused—you can simplify to attr.split('.')[0].
  3. Line 237 uses indexOf('.') >= 0 while line 149 uses .includes('.') for the same check—consider being consistent.
🔧 Suggested style cleanup
-    // Initialize cache value and cache key
-    let cacheVal = val,
-        cacheKey = attr
-    
-    // Handle nested attributes (dot notation)
-    if (attr.indexOf('.') >= 0) {
-      // Split attribute path and use first key for caching
-      const [firstKey, ..._rest] = attr.split('.')
-      cacheKey = firstKey
-      // Get the actual value from server data using first key
-      cacheVal = serverData[firstKey]
-    }
+    // Initialize cache value and cache key
+    let cacheVal = val;
+    let cacheKey = attr;
+
+    // Handle nested attributes (dot notation)
+    if (attr.includes('.')) {
+      // Use first path segment as cache key
+      cacheKey = attr.split('.')[0];
+      // Get the actual value from server data using first key
+      cacheVal = serverData[cacheKey];
+    }
-      const json = encode(cacheVal, false, true)
-      // Store serialized JSON string in object cache
-      objectCache[cacheKey] = JSON.stringify(json)
+      const json = encode(cacheVal, false, true);
+      // Store serialized JSON string in object cache
+      objectCache[cacheKey] = JSON.stringify(json);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ObjectStateMutations.ts` around lines 229 - 256, Fix small style issues
in ObjectStateMutations: add missing semicolons after the declarations for
cacheVal/cacheKey and after storing objectCache to match file style; replace
"const [firstKey, ..._rest] = attr.split('.')" with a simpler extraction (e.g.,
use attr.split('.')[0] to derive firstKey) to remove the unused _rest; and use
the same dot-check style as elsewhere by replacing "attr.indexOf('.') >= 0" with
"attr.includes('.')" so the nestedSet/attr handling and objectCache population
(cacheKey, cacheVal, encode, ParseObject/ParseFile/ParseRelation checks) are
consistent with the rest of the module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/ObjectStateMutations.ts`:
- Around line 229-256: Fix small style issues in ObjectStateMutations: add
missing semicolons after the declarations for cacheVal/cacheKey and after
storing objectCache to match file style; replace "const [firstKey, ..._rest] =
attr.split('.')" with a simpler extraction (e.g., use attr.split('.')[0] to
derive firstKey) to remove the unused _rest; and use the same dot-check style as
elsewhere by replacing "attr.indexOf('.') >= 0" with "attr.includes('.')" so the
nestedSet/attr handling and objectCache population (cacheKey, cacheVal, encode,
ParseObject/ParseFile/ParseRelation checks) are consistent with the rest of the
module.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf05eab1-f6b4-4235-af44-6a1eba436e5b

📥 Commits

Reviewing files that changed from the base of the PR and between cc74316 and b94ec75.

📒 Files selected for processing (1)
  • src/ObjectStateMutations.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants