Skip to content
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

fix: Saving object with a pointer field set to undefined throws error for Postgres #9147

Open
wants to merge 7 commits into
base: alpha
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions spec/PostgresStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,35 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
await adapter.deleteIdempotencyFunction();
await client.none(qs);
});

it('saves object with a pointer field set to undefined', async () => {
Copy link
Member

@mtrezza mtrezza Jun 7, 2024

Choose a reason for hiding this comment

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

This test should be moved to where the existing pointer tests are, as it's not a postgres specific test, even if the issue occurs only with postgres.

mtrezza marked this conversation as resolved.
Show resolved Hide resolved
const pointerTestClassName = 'PointerTest';
const pointerTestSchema = new Parse.Schema(pointerTestClassName);
await pointerTestSchema.save();

// Make another class 'Test' with a pointer field to the first class
const testClassName = 'Test';
const testSchema = new Parse.Schema(testClassName);
const pointerToFieldName = 'pointerTo';
testSchema.addPointer(pointerToFieldName, pointerTestClassName); // Field points to Pointer Test
await testSchema.save();

// Create a 'Test' parse object with the 'pointerTo' field set to undefined
const obj = new Parse.Object(testClassName);
obj.set(pointerToFieldName, undefined);
expectAsync(obj.save()).toBeResolved();

// Create a 'Test parse object with the fields set to undefined directly in the constructor
const fields = {
[pointerToFieldName]: undefined,
};
const obj2 = new Parse.Object(testClassName, fields);
expectAsync(obj2.save()).toBeResolved();

// Create a 'Test' parse object with the fields set to undefined directly in the save method
const obj3 = new Parse.Object(testClassName);
expectAsync(obj3.save(fields)).toBeResolved();
});
});

describe_only_db('postgres')('PostgresStorageAdapter shutdown', () => {
Expand Down
Loading