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

When the pulled documents in the replication do not match the schema, do not update the checkpoint. #6684

Merged
merged 3 commits into from
Dec 16, 2024
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
1 change: 1 addition & 0 deletions docs-src/docs/releases/16.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ I completely rewrote them and improved performance especially on initial load wh
- Throw error when dexie.js RxStorage is used with optional index fields [#6643](https://github.com/pubkey/rxdb/pull/6643#issuecomment-2505310082).
- Fix IndexedDB bug: Some people had problems with the IndexedDB RxStorage that opened up collections very slowly. If you had this problem, please try out this new version.
- Add check to ensure remote instances are build with the same RxDB version. This is to ensure if you update RxDB and forget to rebuild your workers, it will throw instead of causing strange problems.
- When the pulled documents in the replication do not match the schema, do not update the checkpoint.

## Other

Expand Down
14 changes: 11 additions & 3 deletions src/replication-protocol/downstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type {
ById,
WithDeleted,
DocumentsWithCheckpoint,
WithDeletedAndAttachments
WithDeletedAndAttachments,
RxError
} from '../types/index.d.ts';
import {
appendToArray,
Expand Down Expand Up @@ -472,6 +473,7 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any
state.events.processed.down.next(writeRowsToForkById[docId]);
useMetaWriteRows.push(writeRowsToMeta[docId]);
});
let mustThrow: RxError | undefined;
forkWriteResult.error.forEach(error => {
/**
* We do not have to care about downstream conflict errors here
Expand All @@ -481,10 +483,16 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any
return;
}
// other non-conflict errors must be handled
state.events.error.next(newRxError('RC_PULL', {
const throwMe = newRxError('RC_PULL', {
writeError: error
}));
});
state.events.error.next(throwMe);
mustThrow =
mustThrow = throwMe;
});
if (mustThrow) {
throw mustThrow;
}
});
}
}).then(() => {
Expand Down
19 changes: 17 additions & 2 deletions test/unit/replication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ describe('replication.test.ts', () => {
const amount = 5;
const { localCollection, remoteCollection } = await getTestCollections({ local: 0, remote: amount });

// // add onee that still matches the schema
// await remoteCollection.insert({
// id: 'matches-schema',
// name: 'foobar',
// updatedAt: 1001,
// age: 0
// });

/**
* Use collection with different schema
* to provoke validation errors.
Expand All @@ -359,7 +367,7 @@ describe('replication.test.ts', () => {
const replicationState = replicateRxCollection({
collection: otherSchemaCollection as any,
replicationIdentifier: REPLICATION_IDENTIFIER_TEST,
live: false,
live: true,
pull: {
handler: getPullHandler(remoteCollection)
},
Expand All @@ -378,9 +386,16 @@ describe('replication.test.ts', () => {
assert.strictEqual(docsLocal.length, 0);


assert.strictEqual(errors.length, amount);
// assert.strictEqual(errors.length, amount);
assert.ok(JSON.stringify(errors[0].parameters).includes('maximum'));

const pullCheckpointAfter = await getLastCheckpointDoc(
ensureNotFalsy(replicationState.internalReplicationState),
'down'
);

// when all pulls failed, it should not have the checkpoint updated
assert.ok(!pullCheckpointAfter);

localCollection.database.close();
remoteCollection.database.close();
Expand Down