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

Inserting without an optional index field causes unexpected behavior #6643

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

OskarD
Copy link

@OskarD OskarD commented Nov 27, 2024

This PR contains:

A BUG REPORT

Describe the problem you have without this PR

Documents inserted with a (not required) empty index field behave unexpectedly

Todos

  • Tests
  • Documentation
  • Typings
  • Changelog

@@ -9,7 +9,6 @@
* - 'npm run test:browser' so it runs in the browser
Copy link
Author

@OskarD OskarD Nov 27, 2024

Choose a reason for hiding this comment

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

Bonus: This script does not exist

@OskarD OskarD changed the title Add failing test Inserting without an optional index field causes unexpected behavior Nov 27, 2024
@pubkey
Copy link
Owner

pubkey commented Nov 27, 2024

Thanks for the PR. Indeed it looks like there is a bug. I will check.

@pubkey
Copy link
Owner

pubkey commented Nov 28, 2024

Ok so the query plan looks correct:

"preparedQuery": {
        "query": {
            "selector": {
                "_deleted": {
                    "$eq": false
                }
            },
            "sort": [
                {
                    "id": "asc"
                }
            ],
            "skip": 0
        },
        "queryPlan": {
            "index": [
                "_deleted",
                "numberIndex",
                "id"
            ],
            "startKeys": [
                false,
                -9007199254740991,
                -9007199254740991
            ],
            "endKeys": [
                false,
                "",
                ""
            ],
            "inclusiveEnd": true,
            "inclusiveStart": true,
            "sortSatisfiedByIndex": false,
            "selectorSatisfiedByIndex": true
        }
    }

I played around with the generated keyrange but I am not sure if this is even fixable.

@pubkey
Copy link
Owner

pubkey commented Nov 28, 2024

I found out:
As David Fahlander from dexie.js explains here, undefined is not an indexable type. So this cannot be fixed. We should add a check to the dexie.js RxStorage to throw a proper error when this type of schema is used. Just returning wrong results is not a correct behavior.

The premium IndexedDB RxStorage from RxDB does not have this problem because it uses custom index strings, not the composite index keys from native IndexedDB.

pubkey added a commit that referenced this pull request Nov 28, 2024
pubkey added a commit that referenced this pull request Nov 28, 2024
* ADD test for #6643

* ADD docs

* ADD throw correct error

* FIX tests

* FIX schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants