parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

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`

Open RahulLanjewar93 opened this issue 6 months ago • 7 comments
trafficstars

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

  • [x] 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.

RahulLanjewar93 avatar Apr 30 '25 10:04 RahulLanjewar93

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

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

📝 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

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

coderabbitai[bot] avatar Apr 30 '25 10:04 coderabbitai[bot]

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

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

parseplatformorg avatar Apr 30 '25 10:04 parseplatformorg

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Apr 30 '25 10:04 codecov[bot]

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

RahulLanjewar93 avatar Apr 30 '25 11:04 RahulLanjewar93

@mtrezza This is also a bug. added a fix

RahulLanjewar93 avatar May 01 '25 18:05 RahulLanjewar93