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

Adding tree ranks to queries will incorrectly filter valid records #5479

Open
realVinayak opened this issue Dec 17, 2024 · 0 comments
Open
Labels
1 - Bug Incorrect behavior of the product

Comments

@realVinayak
Copy link
Contributor

realVinayak commented Dec 17, 2024

Related to code I pushed a while ago. Wanted to make this issue before but just got time. Introduced in #5036.

There's a bug below

new_filters = [*query.internal_filters, getattr(node, treedef_column).in_(defs_to_filter_on)]

It'll always apply the in predicate. That means if you make a query like Determination -> Taxon (species) -> Fullname, with "any" filter, determinations without a taxon will be absent. This is not correct, and a regression

I haven't tested this anywhere yet (since sp7demofish still seems to run 7.9.6.2). If someone on testing could verify this, it'll be good.

Instructions

  1. Make a collectionobject. Assign taxon (species) to it. You could technically assign anything, but for simplicity just assign species OR remember what rank was assigned.
  2. Make another collectionobject, Do not assign taxon to it.

Run the following query. Basically Determination -> Taxon (species) -> Fullname
image

You'll notice that only collectionobject from first step is returned, and from second step is not returned (even though it should, just blank for species field).

This bug is on production, and not on 7.9.6.2, so couldn't test it myself.

The correct fix would be to change the predicate to be

new_filters = [*query.internal_filters, getattr(node, treedef_column).in_(defs_to_filter_on)]

import sqlalchemy
sqlalchemy.or_(getattr(node, treedef_column).in_(defs_to_filter_on), getattr(node, treedef_column) == None)

Technically you could push None outside, but query optimizers should optimize that out anyways

Not related to #5402. 🤯

@realVinayak realVinayak added the 1 - Bug Incorrect behavior of the product label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Bug Incorrect behavior of the product
Projects
None yet
Development

No branches or pull requests

1 participant