Skip to content

Inserting without an optional index field causes unexpected behavior#6643

Closed
OskarD wants to merge 2 commits into
pubkey:masterfrom
OskarD:patch-1
Closed

Inserting without an optional index field causes unexpected behavior#6643
OskarD wants to merge 2 commits into
pubkey:masterfrom
OskarD:patch-1

Conversation

@OskarD

@OskarD OskarD commented Nov 27, 2024

Copy link
Copy Markdown
Contributor

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

@OskarD OskarD Nov 27, 2024

Copy link
Copy Markdown
Contributor Author

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

pubkey commented Nov 27, 2024

Copy link
Copy Markdown
Owner

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

@pubkey

pubkey commented Nov 28, 2024

Copy link
Copy Markdown
Owner

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

pubkey commented Nov 28, 2024

Copy link
Copy Markdown
Owner

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
@pubkey pubkey closed this Dec 8, 2024
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