- Fixed get_default_valid_fields() and get_valid_fields() methods in filters.py
- Changed context={} default parameter to context=None to prevent mutable default anti-pattern
- Added proper None checking with context = {} assignment inside methods
Why this fix is important:
- Mutable default arguments (context={}) create shared state across function calls
- Same dict object gets reused, potentially causing unexpected side effects
- This is a well-known Python anti-pattern that can lead to bugs
What was changed:
- Line 249: get_default_valid_fields(self, queryset, view, context=None)
- Line 285: get_valid_fields(self, queryset, view, context=None)
- Added 'if context is None: context = {}' in both methods
Testing results:
- All existing filter tests pass (pytest tests/test_filters.py)
- Custom verification script confirms fix works correctly
- Maintains backward compatibility
- No breaking changes to API
Addresses GitHub issue #9741
* Fix : Updated documentation in tutorial 5 leading to error
* Updated docs/tutorial/5-relationships-and-hyperlinked-apis.md
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
* Missing newline
---------
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
* Drop HTML line breaks on long headers
* Remove related test
* Fix flake8
---------
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
* Add failing test for `UniqueConstraint` validation with `source` attribute
* Fix `UniqueTogetherValidator` to handle fields with source attribute
* split inner sources logic out to tuple comprehension
* Start drafting release notes from 3.16 (Generated from GitHub)
* Reformat changes and split into sections
* Format GitHub PRs links for the docs
* Link new contributors in Markdown format
* Write up 3.16 announcement
* Bump version
* Add entry for removed Python 3.8 support
* Update release date to 28/03
* Minor rewording
* Add 3.16 announcement to the navbar and link to docs
* Fix typo of 'related' in tests
* Fix typo of permission_classes in coreapi test
* Fix some minor typos in docs
* Fix typos in tests
* Fix flake8 issue
* Fixed regression that tests using format still work
Error only occurred on tests which return no content and use
a renderer without charset (e.g. JSONRenderer)
* Fixed linting
* Used early return as before
* Move ret str check back to where it was
* Add test to reproduce problem with nullable fields part of a unique constraint
Ref #9378
* Simplify test case and add similar case for unique_together
* Add test for unique together in a better place
* Default nullable fields to null in unique constraints checks
* Remove redundant test and move other to more appropriate place
* update Django for APIs book cover
* remove retired course from Treehouse
* add DCUS2018 talk, update links from wsvincent.com tutorials to learndjango.com
Making explicit the http GET method of the httpie calls.
For some reason it is sending a POST instead of a GET request as it should be described here:
https://httpie.io/docs/cli/optional-get-and-post
Note:
I was following the docs and testing it within the Git Bash windows console app for making the requests and debugging the DRF projenct in pycharm.