mirror of
https://github.com/appy-one/acebase.git
synced 2026-05-25 06:02:14 -06:00
[GH-ISSUE #135] Unexpected query filter behavior for contains operator when compare == []. #77
Labels
No labels
IndexedDB
browser
bug
dependencies
documentation
duplicate
enhancement
feature request
indexes
indexes
invalid
pull-request
query
question
transaction logging
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase#77
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SilentAntenna on GitHub (Aug 9, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/135
Originally assigned to: @appy-one on GitHub.
According to the description of operator
contains, whencompare == [], the query should return all values in the database. But actually it returns nothing.Note that
compare == []is possible in actual use. It may be followed by other query operations likesortandtake.@appy-one commented on GitHub (Aug 9, 2022):
The docs say:
It does not say it will match all records if you pass an empty array. I think that if you pass an empty array, it should match only nodes with empty array values.
If this is not the case, or can convince me that logic should be different, let me know. Also, please provide code examples with expected and actual output, so I can add them to the unit tests.
@SilentAntenna commented on GitHub (Aug 10, 2022):
Note: My bad. The database didn't return an empty set when
compare == []. It actually threw an uncaught error. I didn't notice that because my error handler caught it in my own code.Nevertheless, it is still a very dangerous behavior. And the error condition is not stated in the document.
Imagine an item list with property
tags. We usequery('address').filter('tags', 'contains', filter_tag_list).get()to get the items with related tags. If we add a new element infilter_tag_list, we will have more constraints in our query and fewer items will be returned. Now let's reverse the process. If we delete an element infilter_tag_list, we will have less constraints in our query and get more items, if we delete all the elements infilter_tag_list, there will be no constraint in our query at all.Code example:
@appy-one commented on GitHub (Aug 15, 2022):
Thanks for your detailed explanation! I'll add a unit test with your code and make appropriate adjustments.
@appy-one commented on GitHub (Aug 15, 2022):
I've made quite a few changes to the code today, managed to tackle this issue too. I'll try to release a new version within a week or so, if you'd want to test with the new codebase before then (I'm in the middle of a TypeScript port), make sure to clone both the acebase and acebase-core repositories!
@appy-one commented on GitHub (Aug 19, 2022):
I published the fix in v1.22.0!
@SilentAntenna commented on GitHub (Aug 20, 2022):
The filter is working as expected now. Thanks!