Skip to content

fix: LiveQuery throws on create event using Parse.Query.containedIn with null value in array or using Parse.Query.equalTo for Parse.Object with key value null #9744

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 7 commits into
base: alpha
Choose a base branch
from

Conversation

RahulLanjewar93
Copy link
Contributor

@RahulLanjewar93 RahulLanjewar93 commented Apr 30, 2025

Pull Request

Issue

Live query throw error if we create subsciption for

  1. ParentObjectQuery.containedIn('childs', [...childs,null]) and a ParentObject is created with ParentObject.set('childs',[newChild]
  2. ParentObjectQuery.equalTo('child', child) and a ParentObject is created with ParentObject.set('child',null)

Closes: FILL_THIS_OUT

Approach

Add not null and not object check before doing the actual checks

Tasks

  • Add tests

Summary by CodeRabbit

  • Tests
    • Added new test cases to ensure live queries involving pointer fields and null values operate reliably without causing server errors or crashes.
  • Bug Fixes
    • Improved stability by adding checks to prevent errors when handling null or undefined pointer values in live queries.

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: live query throws error fix: Live query throws error Apr 30, 2025
Copy link

parse-github-assistant bot commented Apr 30, 2025

🚀 Thanks for opening this pull request!

❌ Please fill out all fields with a placeholder FILL_THIS_OUT. If a field does not apply to the pull request, fill in n/a or delete the line.

Copy link

coderabbitai bot commented Apr 30, 2025

📝 Walkthrough

Walkthrough

Two new focused test cases were added to the ParseLiveQuery test suite. These tests configure the server to enable live queries on the TestObject class and start the live query server. The first test examines the server's stability when handling a containedIn constraint on a pointer array field, ensuring no crashes occur when saving objects with different pointer arrays. The second test checks the server's behavior with an equalTo constraint on a pointer field, specifically when new objects are created with a null value. Both tests focus on confirming server robustness in handling pointer fields and null values. Additionally, two null checks were added in pointer comparison logic within the live query utility functions to prevent runtime errors.

Changes

File(s) Change Summary
spec/ParseLiveQuery.spec.js Added two focused test cases verifying live query stability with pointer array and pointer field constraints involving null values.
src/LiveQuery/QueryTools.js Added null checks in pointer comparison functions (contains and matchesKeyConstraints) to avoid runtime errors from null or undefined pointers.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase as Test Case
    participant Server as Server
    participant LiveQuery as Live Query Server
    participant Client as Client

    TestCase->>Server: Configure live query for TestObject
    TestCase->>LiveQuery: Start live query server
    Client->>LiveQuery: Subscribe to query (with pointer constraint)
    Client->>Server: Save new TestObject (with pointer array or null)
    LiveQuery->>Client: Emit 'create' event (if applicable)
    Note right of LiveQuery: Ensure no server errors or crashes
Loading

🪧 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.

@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)

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: 3

🧹 Nitpick comments (5)
spec/ParseLiveQuery.spec.js (5)

1328-1328: Remove trailing whitespace

There's a trailing whitespace on this line.

-    await child3.save();
-    
+    await child3.save();
🧰 Tools
🪛 ESLint

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

(no-trailing-spaces)


1331-1331: Remove trailing whitespace

There's a trailing whitespace on this line.

-    query.containedIn('childs', [child1, child2, null]);
-    
+    query.containedIn('childs', [child1, child2, null]);
🧰 Tools
🪛 ESLint

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

(no-trailing-spaces)


1357-1357: Remove trailing whitespace

There's a trailing whitespace on this line.

-    query.equalTo('child', child);
-    
+    query.equalTo('child', child);
🧰 Tools
🪛 ESLint

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

(no-trailing-spaces)


1332-1339: Consider adding assertions to verify behavior

Currently, the test just ensures the server doesn't crash, but it would be better to assert the expected behavior. Consider adding assertions to verify that objects with different child arrays than the query are correctly handled.

     subscription.on('create', () => {});
 
     // Do not need any expect block, just make sure that the server doesn't crash or throw error
     const object1 = new TestObject();
     object1.set('childs', [child3]);
     await object1.save();
+    
+    // Add assertion to verify that the subscription doesn't receive a notification
+    // Wait a short time to ensure any event would have been processed
+    await new Promise(resolve => setTimeout(resolve, 100));
+    expect(subscription.subscribed).toBe(true); // Verify subscription is still active
🧰 Tools
🪛 ESLint

[error] 1336-1336: 'TestObject' is not defined.

(no-undef)


1359-1365: Consider adding assertions to verify behavior

Similar to the first test, this test just ensures the server doesn't crash, but it would be better to assert the expected behavior. Consider adding assertions to verify that objects with null pointer fields are correctly handled.

     subscription.on('create', () => {});
 
     // Do not need any expect block, just make sure that the server doesn't crash or throw error
     const object1 = new TestObject();
     object1.set('child', null);
     await object1.save();
+    
+    // Add assertion to verify that the subscription doesn't receive a notification
+    // Wait a short time to ensure any event would have been processed
+    await new Promise(resolve => setTimeout(resolve, 100));
+    expect(subscription.subscribed).toBe(true); // Verify subscription is still active
🧰 Tools
🪛 ESLint

[error] 1362-1362: 'TestObject' 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 ef665a6 and bcc0fb3.

📒 Files selected for processing (1)
  • spec/ParseLiveQuery.spec.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
spec/ParseLiveQuery.spec.js

[error] 1312-1312: Don't focus the test.

The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.

(lint/suspicious/noFocusedTests)


[error] 1342-1342: Don't focus the test.

The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.

(lint/suspicious/noFocusedTests)

🪛 ESLint
spec/ParseLiveQuery.spec.js

[error] 1312-1312: 'fit' is not defined.

(no-undef)


[error] 1313-1313: 'reconfigureServer' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1329-1329: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1336-1336: 'TestObject' is not defined.

(no-undef)


[error] 1342-1342: 'fit' is not defined.

(no-undef)


[error] 1343-1343: 'reconfigureServer' is not defined.

(no-undef)


[error] 1355-1355: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1362-1362: 'TestObject' is not defined.

(no-undef)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Docker Build

@RahulLanjewar93 RahulLanjewar93 changed the title fix: Live query throws error fix: Live query throws error if a key contains null value in db or new object is created with value as null Apr 30, 2025
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/ParseLiveQuery.spec.js (1)

1328-1328: Minor: Remove trailing whitespace.

There are a few lines with trailing whitespace that should be removed to follow coding style guidelines and avoid linting errors.

-    
+

Also applies to: 1331-1331, 1357-1357

🧰 Tools
🪛 ESLint

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

(no-trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bcc0fb3 and 7e39947.

📒 Files selected for processing (2)
  • spec/ParseLiveQuery.spec.js (1 hunks)
  • src/LiveQuery/QueryTools.js (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
spec/ParseLiveQuery.spec.js (5)
spec/helper.js (3)
  • reconfigureServer (171-205)
  • Parse (4-4)
  • TestObject (257-259)
spec/ParseQuery.spec.js (2)
  • Parse (7-7)
  • TestObject (2937-2937)
spec/ParseLiveQueryServer.spec.js (7)
  • Parse (1-1)
  • subscription (354-354)
  • subscription (413-413)
  • subscription (468-473)
  • subscription (1192-1194)
  • subscription (1205-1207)
  • subscription (1894-1896)
spec/ParseGeoPoint.spec.js (1)
  • TestObject (5-5)
spec/ParsePolygon.spec.js (1)
  • TestObject (1-1)
🪛 ESLint
spec/ParseLiveQuery.spec.js

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

(no-undef)


[error] 1313-1313: 'reconfigureServer' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1329-1329: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1336-1336: 'TestObject' is not defined.

(no-undef)


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

(no-undef)


[error] 1343-1343: 'reconfigureServer' is not defined.

(no-undef)


[error] 1355-1355: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1362-1362: 'TestObject' is not defined.

(no-undef)

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

102-102: Good addition of null check to prevent runtime errors.

This is a robust defensive check that ensures ptr is not null before attempting to access its properties. It prevents potential runtime errors when handling pointer fields that could be null, which directly addresses the first issue mentioned in the PR regarding containedIn queries with null values.


215-215: Well-placed null check for pointer comparison.

Adding this null check prevents runtime errors when comparing objects where one might be null. This directly addresses the second issue in the PR regarding equalTo constraints where the field value could be null.

spec/ParseLiveQuery.spec.js (2)

1312-1339: Good test case for the containedIn null pointer issue.

This test effectively validates the fix for the first scenario described in the PR where live queries would fail when using containedIn with an array containing null. The test creates a subscription with a mixed array of pointers and null, then verifies the server doesn't crash when a new object is saved with a different pointer array.

Note that this test doesn't make assertions, as it's focused on stability testing (ensuring no errors are thrown).

🧰 Tools
🪛 ESLint

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

(no-undef)


[error] 1313-1313: 'reconfigureServer' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1329-1329: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1336-1336: 'TestObject' is not defined.

(no-undef)


1342-1365: Good test case for the equalTo null pointer issue.

This test validates the fix for the second scenario described in the PR, ensuring live queries don't crash when using equalTo with a pointer and handling objects where that field is set to null. The test properly sets up a subscription with an equalTo constraint, then creates an object with the pointer field set to null.

As with the previous test, it focuses on stability rather than making assertions, which is appropriate for this type of error-prevention test.

🧰 Tools
🪛 ESLint

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

(no-undef)


[error] 1343-1343: 'reconfigureServer' is not defined.

(no-undef)


[error] 1355-1355: 'TestObject' is not defined.

(no-undef)


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

(no-trailing-spaces)


[error] 1362-1362: 'TestObject' is not defined.

(no-undef)

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #9744   +/-   ##
=======================================
  Coverage   93.00%   93.00%           
=======================================
  Files         187      187           
  Lines       15082    15082           
  Branches      174      174           
=======================================
  Hits        14027    14027           
  Misses       1043     1043           
  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.

@RahulLanjewar93
Copy link
Contributor Author

The title could have been better but I'm out of ideas

@RahulLanjewar93
Copy link
Contributor Author

@mtrezza This is also a bug. added a fix

const subscription = await query.subscribe();
subscription.on('create', () => {});

// Do not need any expect block, just make sure that the server doesn't crash or throw error
Copy link
Member

Choose a reason for hiding this comment

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

Add expect, presumably await expectAsync(...).toBeResolved();?

// Do not need any expect block, just make sure that the server doesn't crash or throw error
const object1 = new TestObject();
object1.set('child', null);
await object1.save();
Copy link
Member

Choose a reason for hiding this comment

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

Add expect

});


it('Live query should work if we set equalTo(someKey,someParseObject) and new Parse object is created but someKey = null', async () => {
Copy link
Member

@mtrezza mtrezza May 3, 2025

Choose a reason for hiding this comment

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

Test descriptions should be more concise, see others for examples. If there is anything important that requires a longer explanation you could add a comment block inside the test.

Suggested change
it('Live query should work if we set equalTo(someKey,someParseObject) and new Parse object is created but someKey = null', async () => {
it('triggers create event with equalTo for object with key value null', async () => {

@@ -1308,4 +1308,59 @@ describe('ParseLiveQuery', function () {
await new Promise(resolve => setTimeout(resolve, 100));
expect(createSpy).toHaveBeenCalledTimes(1);
});

it('Live query should work if needle is ParsePointer and haystack is any[], checking QueryTools.js>contains', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

more concise test description

@mtrezza mtrezza changed the title fix: Live query throws error if a key contains null value in db or new object is created with value as null fix: LiveQuery throws on create event using Parse.Query.containedIn with null value or Parse.Object is saved with key value as null May 3, 2025
@mtrezza mtrezza changed the title fix: LiveQuery throws on create event using Parse.Query.containedIn with null value or Parse.Object is saved with key value as null fix: LiveQuery throws on create event using Parse.Query.containedIn with null value or Parse.Query.equalTo for Parse.Object key value null May 3, 2025
@mtrezza mtrezza changed the title fix: LiveQuery throws on create event using Parse.Query.containedIn with null value or Parse.Query.equalTo for Parse.Object key value null fix: LiveQuery throws on create event using Parse.Query.containedIn with null value in array or using Parse.Query.equalTo for Parse.Object with key value null May 3, 2025
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.

3 participants