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

RxDB 16.6.1 conflict handler deleted field mismatch #6868

Open
troywweber7 opened this issue Feb 15, 2025 · 3 comments
Open

RxDB 16.6.1 conflict handler deleted field mismatch #6868

troywweber7 opened this issue Feb 15, 2025 · 3 comments
Labels

Comments

@troywweber7
Copy link

troywweber7 commented Feb 15, 2025

On our project we use deleted for the deleted field on our graphql backend, so that means I have set deletedField: 'deleted' on the replication options. When I write a custom conflict handler to try to merge changes, I was surprised to see a discrepancy.

The types for the conflictHandler.resolve method indicate that the shape of assumedMasterState and newDocumentState is identical to the shape of realMasterState. But at runtime, that does not appear to be true.

Since we are using the deletedField option and changing it, I could just account for this in the handler logic by type-asserting that the assumed state and new state actually have a slightly different shape than the real state. I would just make sure to return a resolution that matches the real state. But I figured I should submit an issue just in case anyone else has run into this.

Here is a snippet of the object I console logged.

{
    "newDocumentState": {
        "id": "9b61cadc-c29f-46d5-934b-ba60063f08ee",
        "updatedAt": 1739581928057,
        "firstName": "A",
        "lastName": "Second",
        "companyName": "Second",
        "deleted": true
    },
    "assumedMasterState": {
        "id": "9b61cadc-c29f-46d5-934b-ba60063f08ee",
        "updatedAt": 1739581839714,
        "firstName": "A",
        "lastName": "Second",
        "companyName": "Second",
        "deleted": false
    },
    "realMasterState": {
        "id": "9b61cadc-c29f-46d5-934b-ba60063f08ee",
        "updatedAt": 1739581935975,
        "firstName": "A",
        "lastName": "B",
        "companyName": "Second",
        "_deleted": false
    }
}

The logic would certainly be easier to write/understand if the same field was used at runtime for every entry in the RxConflictHandlerInput<Item>. So is this behaving as expected already? If not, should the values in RxConflictHandlerInput<Item> all have the user configured deleted or the internal RxDB _deleted?

@pubkey
Copy link
Owner

pubkey commented Feb 25, 2025

I think all should have _deleted. The custom deleted field should only be used on the network/sync level, so when data is send to the outside.

@pubkey
Copy link
Owner

pubkey commented Feb 28, 2025

PR welcomed..

Copy link

stale bot commented Mar 7, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

@stale stale bot added the stale label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants