Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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 2 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
2 changes: 1 addition & 1 deletion packages/records/lib/helpers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const formatRecords = ({
const formattedRecord: FormattedRecord = {
id: stableId(datum),
json: datum,
external_id: String(datum['id']),
external_id: String(datum['id']).replaceAll('\x00', ''),
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 @@ -542,6 +542,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
3 changes: 2 additions & 1 deletion packages/records/lib/models/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export async function getRecords({
}

if (externalIds) {
query = query.whereIn('external_id', externalIds);
const cleanIds = externalIds.map((id) => id.replaceAll('\x00', ''));
query = query.whereIn('external_id', cleanIds);
}

if (limit) {
Expand Down
Loading