Repository navigation
Fix TypeError when passing more than two filters to a collection - #761
Open
ranjithguggilla wants to merge 2 commits into
Open
ranjithguggilla wants to merge 2 commits into
ranjithguggilla wants to merge 2 commits into
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Passing three or more filters to a collection raises TypeError before a request is sent:
_get_and_filtercallsand_(*filters), andand_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+andlist. 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 isci.yml, so the badge said the workflow was not found. It now points atci.yml, and the link opens that workflow.I don't have a TPT ticket, so the title check needs the
community-contributionlabel.How to test
The snippet above fails on
devand succeeds on this branch. The client sends the three-element+andheader shown above.test/unit/objects/filtering_test.pyis new. Two of its four tests fail ondev. All four pass here. On Python 3.13.5,make test-unitwas 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 theX-Filterheader.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.ymlURL reads "tests: repo or workflow not found".