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
55 changes: 55 additions & 0 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});

const child1 = new Parse.Object('Child');
await child1.save();
const child2 = new Parse.Object('Child');
await child2.save();
const child3 = new Parse.Object('Child');
await child3.save();

const query = new Parse.Query(TestObject);
query.containedIn('childs', [child1, child2, null]);

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();?

const object1 = new TestObject();
object1.set('childs', [child3]);
await object1.save();
});


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 () => {

await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});

const child = new Parse.Object('Child');
await child.save();

const query = new Parse.Query(TestObject);
query.equalTo('child', child);

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

});
});
3 changes: 2 additions & 1 deletion src/LiveQuery/QueryTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function contains(haystack: Array, needle: any): boolean {
if (typeof ptr === 'string' && ptr === needle.objectId) {
return true;
}
if (ptr.className === needle.className && ptr.objectId === needle.objectId) {
if (ptr && ptr.className === needle.className && ptr.objectId === needle.objectId) {
return true;
}
}
Expand Down Expand Up @@ -212,6 +212,7 @@ function matchesKeyConstraints(object, key, constraints) {
return equalObjectsGeneric(object[key], constraints, function (obj, ptr) {
return (
typeof obj !== 'undefined' &&
obj !== null &&
ptr.className === obj.className &&
ptr.objectId === obj.objectId
);
Expand Down
Loading