Skip to content

fix: Fixed issue where deeply nested keys were having incorrect values #9720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: alpha
Choose a base branch
from

Conversation

RahulLanjewar93
Copy link
Contributor

@RahulLanjewar93 RahulLanjewar93 commented Apr 16, 2025

refer #7385 (comment)

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of keys with dot notation, ensuring nested fields are updated correctly during save operations.
  • Tests

    • Added a new test to verify correct behavior when saving objects with deeply nested keys, specifically validating afterSave triggers and nested field updates.
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: fixed issue where deeply nested keys were having incorrect values Apr 16, 2025
Copy link

parse-github-assistant bot commented Apr 16, 2025

🚀 Thanks for opening this pull request!

Copy link

codecov bot commented Apr 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.00%. Comparing base (0db3a6f) to head (7cf54f0).
Report is 1 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #9720   +/-   ##
=======================================
  Coverage   93.00%   93.00%           
=======================================
  Files         187      187           
  Lines       15082    15073    -9     
  Branches      174      174           
=======================================
- Hits        14027    14019    -8     
+ Misses       1043     1042    -1     
  Partials       12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@dplewis
Copy link
Member

dplewis commented Apr 16, 2025

Looks like it’s failing in Postgres, getting recursive coalesces (dot notation) working would be a challenge

@RahulLanjewar93
Copy link
Contributor Author

Looks like it’s failing in Postgres, getting recursive coalesces (dot notation) working would be a challenge

I'll try to work on this part, do you have any insights on where to look into? I'm not a Postgres expert

@dplewis
Copy link
Member

dplewis commented Apr 16, 2025

Here you go, it might work I'll try as well, might be a week

const handleDotFields = object => {
Object.keys(object).forEach(fieldName => {

@dplewis
Copy link
Member

dplewis commented Apr 16, 2025

@RahulLanjewar93 We can make this test Mongo only as PG Dot notation support is limited already.

@RahulLanjewar93
Copy link
Contributor Author

@RahulLanjewar93 We can make this test Mongo only as PG Dot notation support is limited already.

Ok I'll make changes accordingly then

@RahulLanjewar93 RahulLanjewar93 changed the title fix: Fixed issue where deeply nested keys were having incorrect values Apr 16, 2025
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: fixed issue where deeply nested keys were having incorrect values Apr 16, 2025
Copy link

coderabbitai bot commented Apr 30, 2025

📝 Walkthrough

Walkthrough

The changes simplify the handling of keys containing dots in the buildParseObjects method of RestWrite.js, removing special logic for operation and subdocument keys. Now, all dotted keys are set directly on the updated object without distinction. Additionally, a new test case is added to spec/ParseObject.spec.js to verify correct behavior when saving objects with deeply nested keys, ensuring that afterSave triggers receive the expected nested field values after various modifications.

Changes

File(s) Change Summary
src/RestWrite.js Simplified handling of keys with dots in buildParseObjects by removing special-case logic for operation/subdoc keys; now all dotted keys are set directly on the updated object.
spec/ParseObject.spec.js Added a MongoDB-specific test verifying correct afterSave behavior for deeply nested keys through a sequence of saves and modifications.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant afterSaveTrigger

    Client->>Server: Save GameScore object with nested keys
    Server->>afterSaveTrigger: Invoke afterSave with saved object
    afterSaveTrigger->>Server: Validate nested keys, increment counter
    Server-->>Client: Respond to save request

    Note over Server,afterSaveTrigger: This sequence repeats for each save with modifications to nested keys.
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bb09ff and 7d60238.

📒 Files selected for processing (1)
  • spec/ParseObject.spec.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
spec/ParseObject.spec.js (3)
spec/ParseAPI.spec.js (8)
  • Parse (6-6)
  • object (673-673)
  • object (719-719)
  • obj (38-38)
  • obj (319-319)
  • obj (413-413)
  • obj (691-691)
  • obj (747-747)
spec/helper.js (1)
  • Parse (4-4)
spec/CloudCode.spec.js (11)
  • Parse (3-3)
  • obj (142-142)
  • obj (191-191)
  • obj (210-210)
  • obj (238-238)
  • obj (258-258)
  • obj (305-305)
  • obj (584-584)
  • obj (589-589)
  • obj (610-610)
  • obj (623-623)
🪛 ESLint
spec/ParseObject.spec.js

[error] 2175-2175: 'it_only_db' is not defined.

(no-undef)


[error] 2179-2179: 'expect' is not defined.

(no-undef)


[error] 2183-2183: 'expect' is not defined.

(no-undef)


[error] 2184-2184: 'expect' is not defined.

(no-undef)


[error] 2187-2187: 'expect' is not defined.

(no-undef)


[error] 2188-2188: 'expect' is not defined.

(no-undef)


[error] 2191-2191: 'expect' is not defined.

(no-undef)


[error] 2192-2192: 'expect' is not defined.

(no-undef)


[error] 2195-2195: 'expect' is not defined.

(no-undef)


[error] 2196-2196: 'expect' is not defined.

(no-undef)


[error] 2199-2199: 'expect' is not defined.

(no-undef)


[error] 2200-2200: 'expect' is not defined.

(no-undef)


[error] 2224-2224: 'expect' is not defined.

(no-undef)

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: Redis Cache
  • GitHub Check: Node 20
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: Node 18
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: Docker Build
  • GitHub Check: MongoDB 6, ReplicaSet
🔇 Additional comments (1)
spec/ParseObject.spec.js (1)

2175-2225: Well implemented test case for the bug fix.

This new MongoDB-specific test thoroughly verifies the fix for the issue with deeply nested keys by testing various scenarios:

  1. Creating an object with nested fields
  2. Incrementing values in nested fields
  3. Setting new values in nested fields
  4. Unsetting deeply nested fields
  5. Unsetting intermediate nested fields

The test correctly ensures the afterSave trigger receives the expected values after each operation. Making this test MongoDB-specific aligns with the PR objectives, where it was mentioned that Postgres has limited support for dot notation.

🧰 Tools
🪛 ESLint

[error] 2175-2175: 'it_only_db' is not defined.

(no-undef)


[error] 2179-2179: 'expect' is not defined.

(no-undef)


[error] 2183-2183: 'expect' is not defined.

(no-undef)


[error] 2184-2184: 'expect' is not defined.

(no-undef)


[error] 2187-2187: 'expect' is not defined.

(no-undef)


[error] 2188-2188: 'expect' is not defined.

(no-undef)


[error] 2191-2191: 'expect' is not defined.

(no-undef)


[error] 2192-2192: 'expect' is not defined.

(no-undef)


[error] 2195-2195: 'expect' is not defined.

(no-undef)


[error] 2196-2196: 'expect' is not defined.

(no-undef)


[error] 2199-2199: 'expect' is not defined.

(no-undef)


[error] 2200-2200: 'expect' is not defined.

(no-undef)


[error] 2224-2224: 'expect' is not defined.

(no-undef)


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
@mtrezza
Copy link
Member

mtrezza commented Apr 30, 2025

What's the state of this PR?

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Apr 30, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 30, 2025
@RahulLanjewar93
Copy link
Contributor Author

What's the state of this PR?

I have to change the test to mongo instead of generic test. Have been occupied with something will do it sometime this week

@RahulLanjewar93
Copy link
Contributor Author

What's the state of this PR?

Ready for review/merging

parentVal[splittedKey[1]] = data[key];
updatedObject.set(parentProp, parentVal);
}
updatedObject.set(key, data[key]);
Copy link
Member

Choose a reason for hiding this comment

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

This line replaces a bunch of code. Why was that code not needed, can it just be removed? Looking at this check for example:

if (typeof data[key].__op === 'string') {
        if (!readOnlyAttributes.includes(key)) {
          updatedObject.set(key, data[key]);
        }
      }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the parse js sdk handles it as per @dplewis comment here #7385 (comment)

This pr is just a duplicate for #7385 since its in draft mode.

Copy link
Member

Choose a reason for hiding this comment

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

I see, maybe @dplewis wants to chime in here an approve this since he already looked into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants