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(persist): Filter external ids to remove 0x00 #3498

Merged
merged 5 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/records/lib/helpers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const formatRecords = ({
const formattedRecord: FormattedRecord = {
id: stableId(datum),
json: datum,
external_id: String(datum['id']),
// postgresql does not support null bytes in strings
external_id: String(datum['id']).replaceAll('\x00', ''),
nalanj marked this conversation as resolved.
Show resolved Hide resolved
data_hash,
model,
connection_id: connectionId,
Expand Down
17 changes: 17 additions & 0 deletions packages/records/lib/models/records.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,23 @@ describe('Records service', () => {
expect(records).toContainEqual(expect.objectContaining({ id: '5' }));
});

it('should filter out 0x00 in ids', async () => {
const connectionId = rnd.number();
const environmentId = rnd.number();
const model = rnd.string();
const syncId = uuid.v4();
const toInsert = [{ id: '1', name: 'John Doe' }];
await upsertRecords({ records: toInsert, connectionId, environmentId, model, syncId });

const response = await Records.getRecords({ connectionId, model, externalIds: ['\x001'] });

expect(response.isOk()).toBe(true);
const { records } = response.unwrap();

expect(records.length).toBe(1);
expect(records).toContainEqual(expect.objectContaining({ id: '1', name: 'John Doe' }));
});

it('Should be able to retrieve 20K records in under 5s with a cursor', async () => {
const numOfRecords = 20000;
const limit = 1000;
Expand Down
4 changes: 3 additions & 1 deletion packages/records/lib/models/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export async function getRecords({
}

if (externalIds) {
query = query.whereIn('external_id', externalIds);
// postgresql does not support null bytes in strings
const cleanIds = externalIds.map((id) => id.replaceAll('\x00', ''));
query = query.whereIn('external_id', cleanIds);
}

if (limit) {
Expand Down
Loading