Skip to content

fix: Parse.Query.containedIn and matchesQuery do not work with nested objects #9738

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

Merged
merged 13 commits into from
May 3, 2025

Conversation

RahulLanjewar93
Copy link
Contributor

@RahulLanjewar93 RahulLanjewar93 commented Apr 29, 2025

Pull Request

Issue

#7414

Closes: #7414

Approach

Previously nested objects were converted to Child$ObjectID format before making a query to mongodb. Which was incorrect since nested objects are stored in their object format. Current change handles this edge case. Originally even nested objects should have been stored in Child$ObjectID format. But this is a fix we can provide for now.

Tasks

  • Add tests

Summary by CodeRabbit

  • New Features
    • Improved support for querying nested pointer fields using equalTo, containedIn, and matchesQuery constraints in MongoDB.
  • Tests
    • Added tests to verify correct behavior of queries involving nested pointer fields with equalTo, containedIn, and matchesQuery constraints.

Copy link

The branch release can only be set as base branch by members of @parse-community/core-maintainers.

Pull requests are usually opened against the default branch alpha, which is the working branch. Different repositories may have base branches with different names. If you are sure you need to open this pull request against a different branch, please ask someone from the team mentioned above.

@parse-github-assistant parse-github-assistant bot changed the base branch from release to alpha April 29, 2025 13:30
Copy link

parse-github-assistant bot commented Apr 29, 2025

🚀 Thanks for opening this pull request!

Copy link

coderabbitai bot commented Apr 29, 2025

📝 Walkthrough

"""

Walkthrough

The changes update the logic for transforming query constraints in the MongoDB adapter to correctly handle deeply nested keys, specifically for cases where queries involve nested pointers inside objects or arrays. The transformConstraint function now takes an additional queryKey parameter to determine if a key is nested (contains a dot), and uses this information to select the appropriate transformation function for atoms in the constraint. Corresponding tests have been added to verify that equalTo, containedIn, and matchesQuery work as expected with nested pointer fields in MongoDB.

Changes

File(s) Change Summary
src/Adapters/Storage/Mongo/MongoTransform.js Updated transformConstraint to accept queryKey, determine if key is nested, and select transformation logic accordingly.
spec/ParseQuery.spec.js Added MongoDB-only test suite with tests for equalTo, containedIn, and matchesQuery on deeply nested pointer fields.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite as Test Suite (ParseQuery.spec.js)
    participant ParentObj as Parent Object
    participant ChildObj as Child Object
    participant ParseQuery as Parse.Query
    participant MongoAdapter as Mongo Adapter

    TestSuite->>ChildObj: Create and save Child object
    TestSuite->>ParentObj: Create and save Parent object with nested pointer to Child
    TestSuite->>ParseQuery: Build query with nested pointer constraint (equalTo/containedIn/matchesQuery)
    ParseQuery->>MongoAdapter: Transform query with nested key
    MongoAdapter->>MongoAdapter: Use queryKey to select transformation logic
    MongoAdapter->>MongoAdapter: Apply correct atom transformation for nested keys
    MongoAdapter->>ParseQuery: Return query results
    ParseQuery->>TestSuite: Return parent object(s) matching nested pointer constraint
Loading

Assessment against linked issues

Objective Addressed Explanation
Support deeply nested pointers in 'containedIn' queries (#7414)
Ensure correct query results for equalTo, containedIn, and matchesQuery on nested pointers (#7414)
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.31.1)
spec/ParseQuery.spec.js

📜 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 fc67ed7 and e7836b7.

📒 Files selected for processing (1)
  • spec/ParseQuery.spec.js (1 hunks)
🧰 Additional context used
🪛 ESLint
spec/ParseQuery.spec.js

[error] 5310-5310: 'describe_only_db' is not defined.

(no-undef)


[error] 5311-5311: 'it' is not defined.

(no-undef)


[error] 5315-5315: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5325-5325: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5332-5332: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5333-5333: 'it' is not defined.

(no-undef)


[error] 5337-5337: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5347-5347: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5354-5354: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5355-5355: 'it' is not defined.

(no-undef)


[error] 5359-5359: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5369-5369: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Node 20
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: MongoDB 6, ReplicaSet
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: Docker Build
  • GitHub Check: Code Analysis (javascript)
🔇 Additional comments (4)
spec/ParseQuery.spec.js (4)

5310-5376: New test suite validates the query fixes for nested pointer fields in MongoDB.

This new test suite contains three comprehensive tests that verify the fix for querying nested pointer fields within objects. The tests cover equalTo, containedIn, and matchesQuery constraints, ensuring that each properly handles the nested object structure. The consistent test structure creates a clear pattern to validate that the fix works across different query operators.

🧰 Tools
🪛 ESLint

[error] 5310-5310: 'describe_only_db' is not defined.

(no-undef)


[error] 5311-5311: 'it' is not defined.

(no-undef)


[error] 5315-5315: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5325-5325: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5332-5332: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5333-5333: 'it' is not defined.

(no-undef)


[error] 5337-5337: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5347-5347: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5354-5354: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5355-5355: 'it' is not defined.

(no-undef)


[error] 5359-5359: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5369-5369: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


5312-5332: Good test case for nested equalTo query operator.

The test creates a proper test scenario with a nested pointer field (some.nested.key.child) and verifies that equalTo correctly matches it. This test validates that the equality comparison works properly through multiple levels of nesting.

🧰 Tools
🪛 ESLint

[error] 5315-5315: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5325-5325: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5332-5332: Trailing spaces not allowed.

(no-trailing-spaces)


5334-5354: Good test case for nested containedIn query operator.

This test is essential as it directly addresses the issue mentioned in the PR description where containedIn didn't work with nested objects. The test structure closely mirrors the equalTo test, providing consistency while validating the specific fix for the containment query.

🧰 Tools
🪛 ESLint

[error] 5337-5337: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5347-5347: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5354-5354: Trailing spaces not allowed.

(no-trailing-spaces)


5356-5376: Good test case for nested matchesQuery query operator.

This test properly validates the fix for the matchesQuery operator when used with nested pointer fields. The query pattern demonstrates how a subquery against the Child class can be used to filter Parent objects with nested pointers, completing the verification for all affected query methods.

🧰 Tools
🪛 ESLint

[error] 5359-5359: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5369-5369: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5374-5374: '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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
spec/MongoStorageAdapter.spec.js (1)

398-462: Consider adding negative test cases

While the current tests verify that the query constraints work correctly when there should be a match, it would be beneficial to also test cases where no match should be found.

For example, you could add a test like:

it('Parse query with containedIn returns no results for non-matching object', async () => {
  const child = new Parse.Object('Child')
  child.set('key','value')
  await child.save();
  
  const nonMatchingChild = new Parse.Object('Child')
  nonMatchingChild.set('key','different_value')
  await nonMatchingChild.save();

  const parent = new Parse.Object('Parent');
  parent.set('some', {
    nested: {
      key: {
        child
      }
    }
  })
  await parent.save();

  const query = await new Parse.Query('Parent')
    .containedIn('some.nested.key.child', [nonMatchingChild])
    .find();

  expect(query.length).toEqual(0);
})
🧰 Tools
🪛 ESLint

[error] 398-398: 'it' is not defined.

(no-undef)


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

(no-undef)


[error] 420-420: 'it' is not defined.

(no-undef)


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

(no-undef)


[error] 442-442: 'it' is not defined.

(no-undef)


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

(no-undef)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e556812 and d4da486.

📒 Files selected for processing (1)
  • spec/MongoStorageAdapter.spec.js (1 hunks)
🧰 Additional context used
🪛 ESLint
spec/MongoStorageAdapter.spec.js

[error] 398-398: 'it' is not defined.

(no-undef)


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

(no-undef)


[error] 420-420: 'it' is not defined.

(no-undef)


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

(no-undef)


[error] 442-442: 'it' is not defined.

(no-undef)


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

(no-undef)

🔇 Additional comments (4)
spec/MongoStorageAdapter.spec.js (4)

393-397: Good documentation

The comment clearly explains the issue being fixed - that nested pointer queries work with equalTo but not with containedIn or matchesQuery. This provides valuable context for understanding the tests that follow.


398-418: Well-structured baseline test

This test establishes a baseline by confirming that equalTo works correctly with nested pointers. The test creates the necessary objects, sets up the nested structure properly, and makes a clear assertion.

🧰 Tools
🪛 ESLint

[error] 398-398: 'it' is not defined.

(no-undef)


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

(no-undef)


420-440: Good test for the containedIn fix

This test properly verifies that using containedIn on a nested pointer field works correctly, which addresses part of the issue mentioned in the PR objectives. The structure mirrors the previous test for consistency.

🧰 Tools
🪛 ESLint

[error] 420-420: 'it' is not defined.

(no-undef)


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

(no-undef)


442-462: Comprehensive test for matchesQuery functionality

This test effectively verifies that the matchesQuery constraint works properly with nested pointers, completing the coverage of the fix. The comment noting that this internally uses containedIn helps explain the relationship between the tests.

🧰 Tools
🪛 ESLint

[error] 442-442: 'it' is not defined.

(no-undef)


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

(no-undef)

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Apr 29, 2025

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

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

@RahulLanjewar93
Copy link
Contributor Author

It cancelled the failing test case action -_-
Can someone re run it so that they can see the actual issue

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.

Actionable comments posted: 0

🧹 Nitpick comments (5)
src/Adapters/Storage/Mongo/MongoTransform.js (5)

654-657: Fix for nested object query support in constraints

This change is addressing the core issue in the PR. By accepting the key parameter and checking if it's a nested field (contains a dot), the function can now properly handle query constraints on nested objects.

Note: There is a small typo in the comment: "wether" should be "whether".

- // Check wether the given key has `.`
+ // Check whether the given key has `.`
🧰 Tools
🪛 Biome (1.9.4)

[error] 655-655: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


739-742: Consistently renamed variables in $all handler

The variable renaming is applied throughout the $all constraint handling.

As highlighted by static analysis, consider using Array.isArray() instead of instanceof Array for better compatibility:

-        const arr = constraint[constraintKey];
-        if (!(arr instanceof Array)) {
+        const arr = constraint[constraintKey];
+        if (!Array.isArray(arr)) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 740-740: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


756-757: Renamed variables in regex constraint handling

Variable renamed in the regex constraint handling section.

As noted by static analysis, the variable declaration in a switch case could be improved:

-        var s = constraint[constraintKey];
+        {
+          const s = constraint[constraintKey];
+          if (typeof s !== 'string') {
+            throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad regex: ' + s);
+          }
+          answer[constraintKey] = s;
+        }
-        if (typeof s !== 'string') {
-          throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad regex: ' + s);
-        }
-        answer[constraintKey] = s;

Also applies to: 760-761

🧰 Tools
🪛 Biome (1.9.4)

[error] 756-756: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


764-765: Renamed variables in $containedBy constraint

Variable renaming consistently applied to the $containedBy constraint.

Similar to previous suggestions, consider using Array.isArray():

-        const arr = constraint[constraintKey];
-        if (!(arr instanceof Array)) {
+        const arr = constraint[constraintKey];
+        if (!Array.isArray(arr)) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 765-765: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


850-851: Renamed variables in $within constraint

Variable renaming applied to the $within constraint handler.

As noted by static analysis, this switch clause variable declaration could be wrapped in a block:

-        var box = constraint[constraintKey]['$box'];
+        {
+          const box = constraint[constraintKey]['$box'];
+          if (!box || box.length != 2) {
+            throw new Parse.Error(Parse.Error.INVALID_JSON, 'malformatted $within arg');
+          }
+          answer[constraintKey] = {
+            $box: [
+              [box[0].longitude, box[0].latitude],
+              [box[1].longitude, box[1].latitude],
+            ],
+          };
+        }
-        if (!box || box.length != 2) {
-          throw new Parse.Error(Parse.Error.INVALID_JSON, 'malformatted $within arg');
-        }
-        answer[constraintKey] = {
-          $box: [
-            [box[0].longitude, box[0].latitude],
-            [box[1].longitude, box[1].latitude],
-          ],
-        };

Also applies to: 854-855

🧰 Tools
🪛 Biome (1.9.4)

[error] 850-850: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4da486 and ec45ba0.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Mongo/MongoTransform.js (13 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/Adapters/Storage/Mongo/MongoTransform.js

[error] 655-655: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 724-724: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 740-740: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 756-756: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 850-850: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: MongoDB 6, ReplicaSet
  • GitHub Check: Node 18
  • GitHub Check: Node 20
  • GitHub Check: Redis Cache
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: Docker Build
  • GitHub Check: Code Analysis (javascript)
🔇 Additional comments (24)
src/Adapters/Storage/Mongo/MongoTransform.js (24)

329-330: Properly passing the key parameter to transformConstraint

The key is now correctly passed to the transformConstraint function from the transformQueryKeyValue function, which is essential for the fix to work.


661-662: Essential logic to handle nested fields correctly

This is the critical change that fixes the issue with containedIn and matchesQuery constraints for nested objects. By choosing the appropriate transformation function based on whether the field is an array OR the key is nested, nested pointer fields are now properly transformed.


674-675: Variable renaming for clarity

Renaming keys to constraintKeys improves code clarity and avoids confusion with the outer key parameter.


676-677: Variable renaming to prevent shadowing

Good change to avoid shadowing the key parameter with a loop variable. This improves code maintainability and prevents potential bugs.


685-686: Consistent variable renaming

Continuing the variable renaming pattern to use constraintKey instead of key for consistency within the function.


693-694: Consistent variable renaming

Further applied the variable renaming scheme throughout the switch statement.


706-707: Consistent variable renaming

Variable renaming applied to answer[constraintKey].


713-714: Variable renaming in error message

Consistent renaming in the error message string.


717-718: Final value transformation using the appropriate transformer

This line uses the dynamically selected transformer (which now correctly handles nested fields) to transform the value.


745-746: Variable renaming in relationship extraction

Consistent variable renaming applied to the values extraction.


774-775: Renaming for $options constraint

Variable renaming applied to the $options constraint case.


778-779: Renamed variables in $text constraint

Variable renaming applied in the $text constraint handling section.

Also applies to: 785-786


792-793: Renamed variables in $text options

Consistently renamed variables for additional $text search options.

Also applies to: 800-801, 808-809


813-814: Renamed variables in $nearSphere constraint

Variable renaming applied to the $nearSphere constraint.

Also applies to: 819-820


827-828: Renamed variables in $maxDistance

Variable renaming in the $maxDistance constraint handler.


833-834: Renamed variables in distance-related constraints

Variable renaming consistently applied to the distance-related constraints.

Also applies to: 836-837, 839-840


846-847: Renamed variable in error message

Variable renaming applied to the error message for unsupported constraints.


863-865: Renamed variables in $geoWithin constraint

Variable renaming applied to the $geoWithin constraint handler.


901-903: Renamed variables in polygon handling

Variable renaming applied to the polygon portion of $geoWithin.


930-932: Renamed variables in centerSphere handling

Variable renaming applied to the centerSphere portion of $geoWithin.


937-938: Renamed variables in $geoIntersects constraint

Variable renaming applied to the $geoIntersects constraint handler.

Also applies to: 946-952


955-957: Renamed variables in the default case

Variable renaming applied to the default case that handles custom constraints.


654-962: Overall assessment of the changes to fix nested objects in queries

This is a solid, targeted fix for the issue with querying nested objects. The changes:

  1. Add proper detection of nested fields (containing dots)
  2. Use the correct transformation function for nested fields
  3. Consistently rename variables to avoid shadowing and improve clarity

These changes ensure that constraints like containedIn and matchesQuery work properly with nested objects by correctly transforming the query conditions. The thorough renaming of variables also prevents potential bugs that could arise from variable shadowing.

🧰 Tools
🪛 Biome (1.9.4)

[error] 655-655: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 756-756: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 850-850: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 724-724: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 740-740: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 765-765: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 875-875: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 890-890: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 905-905: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


[error] 913-913: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)


723-726:

✅ Verification successful

Variable renaming for consistency

The renaming is consistently applied throughout the function, including in array value extractions and error messages.


🏁 Script executed:

#!/bin/bash
# Check if there are any remaining instances of unintended 'key' variables that should be 'constraintKey'
# This will help ensure the renaming was comprehensive

rg -A 2 -B 2 "for\s*\(.+\s+key\s+.+\)\s*\{" src/Adapters/Storage/Mongo/MongoTransform.js

Length of output: 181


Variable renaming verified and correct

All instances of constraintKey are used consistently in array access and error messages. The for (var key in mongoObject) loop correctly uses key to iterate over mongoObject properties and does not require renaming.

🧰 Tools
🪛 Biome (1.9.4)

[error] 724-724: Use Array.isArray() instead of instanceof Array.

instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.

(lint/suspicious/useIsArray)

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 29, 2025
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.00%. Comparing base (3271e2a) to head (20f4b73).
Report is 2 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #9738      +/-   ##
==========================================
- Coverage   93.01%   93.00%   -0.02%     
==========================================
  Files         187      187              
  Lines       15081    15082       +1     
  Branches      174      174              
==========================================
- Hits        14028    14027       -1     
- Misses       1041     1043       +2     
  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.

@mtrezza
Copy link
Member

mtrezza commented Apr 29, 2025

Tests should be running now

@RahulLanjewar93
Copy link
Contributor Author

Tests should be running now

i meant the failing test cases were skipped since I pushed a commit before the actions were complete. We need that to see the current behaviour right? Is there a way to retry actions at that specific commit so we can see the failing test cases

@mtrezza
Copy link
Member

mtrezza commented Apr 29, 2025

If you say they failed for you when you ran them locally, then that's fine. I see that all tests are passing now as well, nice!

Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 29, 2025
@mtrezza mtrezza changed the title fix: Fixed issue where containedIn and matchesQuery does not work with nested objects fix: Parse.Query.containedIn and matchesQuery do not work with nested objects Apr 29, 2025
@mtrezza
Copy link
Member

mtrezza commented Apr 29, 2025

Note: it seems that your PR is based on the release branch of your fork, instead of the alpha branch. That doesn't seem to cause any conflicts - surprisingly - but for future PRs, a PR should be based on the same branch as the one it will be merged into.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Adapters/Storage/Mongo/MongoTransform.js (1)

657-657: Consider adding a defensive check for queryKey

While the current implementation works correctly in this context, adding a defensive check for queryKey would improve code robustness.

-  const isNestedKey = queryKey.indexOf('.') > -1;
+  const isNestedKey = queryKey && typeof queryKey === 'string' && queryKey.indexOf('.') > -1;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 628a9a7 and 89f8750.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Mongo/MongoTransform.js (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/Adapters/Storage/Mongo/MongoTransform.js

[error] 655-655: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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

654-658: Good change: Added check for nested keys to determine transformation strategy

This addition correctly identifies nested fields by checking for dots in the key name, which is the appropriate way to detect nested fields in MongoDB document paths.

🧰 Tools
🪛 Biome (1.9.4)

[error] 655-655: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


662-662: Good implementation: Using the appropriate transformation for nested objects

The updated logic now correctly handles nested keys by using transformInteriorAtom instead of transformTopLevelAtom when the key contains a dot. This fixes the issue where nested objects were incorrectly transformed, causing containedIn and matchesQuery operations to fail.


330-330: LGTM: Passing key parameter to transformConstraint

The caller now correctly passes the key parameter to transformConstraint, enabling the nested key detection.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 30, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 30, 2025
@RahulLanjewar93 RahulLanjewar93 requested a review from mtrezza April 30, 2025 19:33
@RahulLanjewar93
Copy link
Contributor Author

Note: it seems that your PR is based on the release branch of your fork, instead of the alpha branch. That doesn't seem to cause any conflicts - surprisingly - but for future PRs, a PR should be based on the same branch as the one it will be merged into.

Have made the required changes

Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
spec/ParseQuery.spec.js (1)

5315-5379: Minor style improvement: remove trailing whitespace

There are several lines in the test functions that have trailing whitespace. While this doesn't affect functionality, removing trailing whitespace is a common code style practice.

You can remove trailing whitespace from lines in this test suite for consistency with the rest of the codebase.

🧰 Tools
🪛 ESLint

[error] 5315-5315: 'it' is not defined.

(no-undef)


[error] 5319-5319: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5333-5333: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5336-5336: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5337-5337: 'it' is not defined.

(no-undef)


[error] 5341-5341: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5355-5355: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5358-5358: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5359-5359: 'it' is not defined.

(no-undef)


[error] 5363-5363: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5377-5377: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ccf5a60 and fc67ed7.

📒 Files selected for processing (1)
  • spec/ParseQuery.spec.js (1 hunks)
🧰 Additional context used
🪛 ESLint
spec/ParseQuery.spec.js

[error] 5310-5310: 'describe_only_db' is not defined.

(no-undef)


[error] 5315-5315: 'it' is not defined.

(no-undef)


[error] 5319-5319: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5333-5333: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5336-5336: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5337-5337: 'it' is not defined.

(no-undef)


[error] 5341-5341: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5355-5355: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


[error] 5358-5358: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5359-5359: 'it' is not defined.

(no-undef)


[error] 5363-5363: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5377-5377: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)

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

5310-5310: Test suite name matches established pattern

This MongoDB-specific test suite follows the pattern used elsewhere in the codebase. It specifically tests the feature that was fixed in this PR, which is handling nested objects in query constraints.

🧰 Tools
🪛 ESLint

[error] 5310-5310: 'describe_only_db' is not defined.

(no-undef)


5311-5314: Good documentation in comment

The comment clearly explains the issue being tested - that comparing nested pointers works with equalTo but previously didn't work with containedIn or matchesQuery. This helps future developers understand the purpose of these tests.


5315-5335: Comprehensive test for equalTo with nested pointers

The test correctly sets up a deeply nested pointer structure and verifies that querying with equalTo finds it properly. The structure some.nested.key.child provides a good test case for the fix, as it requires handling multiple levels of nesting.

🧰 Tools
🪛 ESLint

[error] 5315-5315: 'it' is not defined.

(no-undef)


[error] 5319-5319: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5329-5329: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5333-5333: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


5337-5357: Test confirms containedIn now works with nested pointers

This test case demonstrates that the fix properly handles the containedIn operator with deeply nested pointers. It follows a consistent structure with the previous test, which is good for maintainability.

🧰 Tools
🪛 ESLint

[error] 5337-5337: 'it' is not defined.

(no-undef)


[error] 5341-5341: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5351-5351: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5355-5355: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)


5359-5379: Test confirms matchesQuery now works with nested pointers

This test verifies that the fix also handles the matchesQuery operator with nested pointers. It completes the set of tests needed to confirm all the functionality mentioned in the PR title and description is working correctly.

🧰 Tools
🪛 ESLint

[error] 5359-5359: 'it' is not defined.

(no-undef)


[error] 5363-5363: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5373-5373: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 5377-5377: Trailing spaces not allowed.

(no-trailing-spaces)


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

(no-undef)

coderabbitai[bot]
coderabbitai bot previously approved these changes May 2, 2025
Signed-off-by: Rahul Lanjewar <63550998+RahulLanjewar93@users.noreply.github.com>
@mtrezza
Copy link
Member

mtrezza commented May 2, 2025

This looks good, but the fix for Postgres is still missing, correct? Is there a similar code in the Postgres adapter where the fix can be made, or is that code very different? If it's different and you don't have the knowledge to fix in Postgres, we can merge the fix only for MongoDB for now and create an open issue to fix this also for Postgres at a later time.

@RahulLanjewar93
Copy link
Contributor Author

This looks good, but the fix for Postgres is still missing, correct? Is there a similar code in the Postgres adapter where the fix can be made, or is that code very different? If it's different and you don't have the knowledge to fix in Postgres, we can merge the fix only for MongoDB for now and create an open issue to fix this also for Postgres at a later time.

I haven't checked it, and I don't have enough knowledge to contribute to postgres code, also stuck with some other priorities currently. I can have a look later when I have some bandwidth or if someone else can pick it up that would be helpful.

I think lets merge this one for now?

@mtrezza
Copy link
Member

mtrezza commented May 3, 2025

I think that's fine, also given @dplewis's comment.

@mtrezza mtrezza merged commit 0db3a6f into parse-community:alpha May 3, 2025
24 of 25 checks passed
parseplatformorg pushed a commit that referenced this pull request May 3, 2025
## [8.2.1-alpha.1](8.2.0...8.2.1-alpha.1) (2025-05-03)

### Bug Fixes

* `Parse.Query.containedIn` and `matchesQuery` do not work with nested objects ([#9738](#9738)) ([0db3a6f](0db3a6f))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 8.2.1-alpha.1

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released-alpha Released as alpha version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support deeply nested pointers in 'containedIn' queries
3 participants