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

Collection.delete() fails silently when filter() is used #1381

Closed
epandurski opened this issue Aug 25, 2021 · 3 comments
Closed

Collection.delete() fails silently when filter() is used #1381

epandurski opened this issue Aug 25, 2021 · 3 comments

Comments

@epandurski
Copy link

In this code:

      const n = await this.tasks
        .where({ userId })
        .filter(task => task.taskType === 'DeleteTransfer' && !uris.has(task.transferUri))
        .delete()

this extends Dexie, and task is a table. n is always zero, even when

      await this.tasks
        .where({ userId })
        .filter(task => task.taskType === 'DeleteTransfer' && !uris.has(task.transferUri))
        .toArray()

returns some objects.

I expect either the deletion to be successful, or to throw error. The documentation does not mention any problems with deleting collections that have filter()s applied.

@dfahlander
Copy link
Collaborator

Thanks for the report. Could you create a repro in https://jsitor.com/, https://codesandbox.io/ or jsfiddle? It would help a lot in finding the reason - it may also reveal whether this actually is a bug in dexie or if there is something else that makes it fail.

@epandurski
Copy link
Author

Here is the repro: https://jsitor.com/qPJXVESEcb

@dfahlander
Copy link
Collaborator

Thanks for a great repro! Indeed, this is a bug that occurs when using filter on a collection on a partial index ("virtual index"). In this case "userId" is indexed together with "createdAt" ([userId+createdAt]). If directly indexing userId by itself the bug does not happen. I will investigate virtual-index-middleware.ts to understand if it fails to emulate the DBCursor correctly.

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

No branches or pull requests

2 participants