sarumont / py-trello

Python API wrapper around Trello's API
BSD 3-Clause "New" or "Revised" License
945 stars 330 forks source link

Make consecutive calls work with default query arg #290

Closed dmwyatt closed 4 years ago

dmwyatt commented 5 years ago

In python, mutable default arguments are "remembered" between calls.

The first time you call lst.list_cards_iter(), the value of query will be {}. The next time you call lst.list_cards_iter(), the value of query will be:

{'limit': 300, 'filter': 'all', 'customFieldItems': 'true', 'before': 'blahblahblah'}

...because thats what it gets set to while the method is running the first time.

https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

TimoMorris commented 4 years ago

Just ran across this issue myself. As a workaround, you can explicitly pass in the parameter query={} on each call.

FWIW, the same issue (mutable default argument) occurs in the previous function above where you've fixed it in your pull request. A quick search revealed a couple of others too - I've listed all the occurrences (including the on in your PR) here:

trellolist.py:

trelloclient.py:

Don't know if you fancy amending your PR to include those as well? (or cancelling it and doing a new one - I'm afraid I don't know how these things work! If not, I could have a go myself...)