Skip to content

Fix TypeError when passing more than two filters to a collection - #761

Open
ranjithguggilla wants to merge 2 commits into
linode:devfrom
ranjithguggilla:fix/and-filter-more-than-two
Open

ranjithguggilla wants to merge 2 commits into
linode:devfrom
ranjithguggilla:fix/and-filter-more-than-two

Conversation

@ranjithguggilla

@ranjithguggilla ranjithguggilla commented Nov 21, 2026 •

Copy link
Copy Markdown

Description

Passing three or more filters to a collection raises TypeError before a request is sent:

client.linode.instances(
    Instance.label == "web",
    Instance.region == "us-east",
    Instance.tags.contains("prod"),
)
TypeError: and_() takes 2 positional arguments but 3 were given

_get_and_filter calls and_(*filters), and and_ only accepted two arguments. The filtering docs say any number of filters can be passed.

and_ now takes two or more and puts them all in one +and list. The call above sends:

{"+and": [{"label": "web"}, {"region": "us-east"}, {"tags": {"+contains": "prod"}}]}

One or two filters behave the same as before. or_ still takes two. I can change that the same way if you want.

The tests badge on the README pointed at main.yml. The workflow file is ci.yml, so the badge said the workflow was not found. It now points at ci.yml, and the link opens that workflow.

I don't have a TPT ticket, so the title check needs the community-contribution label.

How to test

The snippet above fails on dev and succeeds on this branch. The client sends the three-element +and header shown above.

python -m pytest test/unit/objects/filtering_test.py -v
make test-unit

test/unit/objects/filtering_test.py is new. Two of its four tests fail on dev. All four pass here. On Python 3.13.5, make test-unit was 521 passed, and isort, autoflake, black, and pylint were clean. I did not run the integration tests or call the live API. The tests check the X-Filter header.

The tests badge URL can be checked at https://img.shields.io/github/actions/workflow/status/linode/linode_api4-python/ci.yml?label=tests. It reads "tests: passing". The old main.yml URL reads "tests: repo or workflow not found".

Collection methods combine their filters with and_(*filters), but and_
only accepted two arguments, so a call such as

    client.linode.instances(
        Instance.label == "web",
        Instance.region == "us-east",
        Instance.tags.contains("prod"),
    )

raised "TypeError: and_() takes 2 positional arguments but 3 were
given". and_ now accepts two or more filters and combines all of them
into one "+and" list.
@ranjithguggilla
ranjithguggilla requested review from a team as code owners November 21, 2026 01:25
@ranjithguggilla
ranjithguggilla requested review from hmorris3293 and psnoch-akamai and removed request for a team November 21, 2026 01:25
The badge looked up main.yml, which is not a workflow in this repo, so it reported that the workflow was not found.

This branch has not been deployed

No deployments
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.

1 participant