Skip to content

Fix #150: reject list filter values with a clear error instead of silently using CONTAINS - #158

Closed
rudra337-lgtm wants to merge 1 commit into
HumanBrainProject:masterfrom
rudra337-lgtm:fix/150-reject-list-filter-values
Closed

rudra337-lgtm wants to merge 1 commit into
HumanBrainProject:masterfrom
rudra337-lgtm:fix/150-reject-list-filter-values

Conversation

@rudra337-lgtm

Copy link
Copy Markdown

Summary

Fixes #150.

get_query_filter_property() picked the filter operator from the type of the whole
value, so a list of Regex or Equals objects fell through to CONTAINS. The
generated query then had a CONTAINS filter whose value was the entire list, silently
changing the meaning of the query. For link-typed properties, a list value would instead
crash with an AttributeError because str.startswith() was called on the list.

The KG query API only supports a single value per filter (the available operators are
IS_EMPTY, STARTS_WITH, ENDS_WITH, CONTAINS, EQUALS, REGEX, each taking one
string), so there is no way to express "any of these values". As the issue suggests,
this change rejects list filter values with a clear TypeError instead of silently
altering the query.

Changes

  • fairgraph/queries.py: raise a TypeError when a filter value is a list, with a
    message explaining that the KG applies a single value per filter.
  • fairgraph/queries.py: correct the Equals docstring, which documented the old
    (wrong) behaviour that a list of Equals is filtered with CONTAINS.
  • test/test_queries.py: add regression tests covering lists of Equals, Regex,
    plain strings, and instance IDs for a link-typed property.

Testing

  • pytest test → 397 passed, 65 skipped (the 3 new parametrized cases and the link
    case fail on master with DID NOT RAISE TypeError, and pass with this fix).
  • flake8 --select=E9,F63,F7,F82 (the CI lint selection) → clean.

Filtering on a list of values (e.g. short_name=[Equals("FOO"), Equals("BAR")])
silently ignored the Regex/Equals marker and generated a CONTAINS filter whose
value was the whole list, changing the meaning of the query without warning.
For link-typed properties a list value would instead crash with an AttributeError
from str.startswith being called on the list.

The KG query API only supports a single value per filter, so there is no way to
express "any of these values". Raise a TypeError for list filter values instead
of silently altering the query, and document the single-value restriction in the
Equals docstring.

Fixes HumanBrainProject#150
@apdavison

Copy link
Copy Markdown
Member

Thanks for working on this! This was unfortunate timing, as a solution was already in the works - #150 has now been fixed by #156, which supports lists of filter values: each value becomes its own filter, and a result must match all of them. So I'm closing this PR. I appreciate you taking the time, and contributions on other open issues are very welcome.

@apdavison apdavison closed this Oct 17, 2026
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.

Filtering on a list of values silently ignores Regex/Equals and sends CONTAINS with a list value

2 participants