-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix URLPathVersioning reverse fallback #7247
Conversation
Hi @jornvanwier. Could you add a test case that demonstrates the failure? |
Hi @rpkilby, I was unable to get the ReverseView that's used in the other test to show the issue, so I manually called into the reverse function (much like how I'm using it where I first encountered the problem). I hope that's ok. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes 2 things. It makes version_param
in kwargs
take precedence over the request.version
and it stops modifying the given kwargs
, thus stop potentially leaking into other contexts.
This might impact existing users, but it is imho the right thing to do. I'll approve but would prefer if someone else had a quick look too.
* fix URLPathVersioning reverse fallback * add test for URLPathVersioning reverse fallback * Update tests/test_versioning.py --------- Co-authored-by: Jorn van Wier <[email protected]> Co-authored-by: Asif Saif Uddin <[email protected]>
* fix: Make the instance variable of child serializer point to the correct list object instead of the entire list when validating ListSerializer * fix formatting issues for list serializer validation fix * fix imports sorting for list serializer tests * remove django 2.2 from docs index (#8982) * Declared Django 4.2 support in README.md (#8985) * Fix Links in Documentation to Django `reverse` and `reverse_lazy` (#8986) * Fix Django Docs url in reverse.md Django URLs of the documentation of `reverse` and `reverse_lazy` were wrong. * Update reverse.md * fix URLPathVersioning reverse fallback (#7247) * fix URLPathVersioning reverse fallback * add test for URLPathVersioning reverse fallback * Update tests/test_versioning.py --------- Co-authored-by: Jorn van Wier <[email protected]> Co-authored-by: Asif Saif Uddin <[email protected]> * Make set_value a method within `Serializer` (#8001) * Make set_value a static method for Serializers As an alternative to #7671, let the method be overridden if needed. As the function is only used for serializers, it has a better place in the Serializer class. * Set `set_value` as an object (non-static) method * Add tests for set_value() These tests follow the examples given in the method. * fix: Make the instance variable of child serializer point to the correct list object instead of the entire list when validating ListSerializer * Make set_value a method within `Serializer` (#8001) * Make set_value a static method for Serializers As an alternative to #7671, let the method be overridden if needed. As the function is only used for serializers, it has a better place in the Serializer class. * Set `set_value` as an object (non-static) method * Add tests for set_value() These tests follow the examples given in the method. * fix: Make the instance variable of child serializer point to the correct list object instead of the entire list when validating ListSerializer * fix: Make the instance variable of child serializer point to the correct list object instead of the entire list when validating ListSerializer * fix formatting issues for list serializer validation fix * fix: Make the instance variable of child serializer point to the correct list object instead of the entire list when validating ListSerializer * fix formatting issues for list serializer validation fix * fix linting * Update rest_framework/serializers.py Co-authored-by: Sergei Shishov <[email protected]> * Update rest_framework/serializers.py Co-authored-by: Sergei Shishov <[email protected]> * fix: instance variable in list serializer, remove commented code --------- Co-authored-by: Mathieu Dupuy <[email protected]> Co-authored-by: Mehraz Hossain Rumman <[email protected]> Co-authored-by: Dominik Bruhn <[email protected]> Co-authored-by: jornvanwier <[email protected]> Co-authored-by: Jorn van Wier <[email protected]> Co-authored-by: Asif Saif Uddin <[email protected]> Co-authored-by: Étienne Beaulé <[email protected]> Co-authored-by: Sergei Shishov <[email protected]>
When using URLPathVersioning
reverse
addsrequest.version
to the kwargs and tries to find a match. If that fails, it falls back to the defaultreverse
function (which doesn't add the version to the kwargs.However, without this fix the kwargs parameter is modified, which leads to the fallback
reverse
function having the same behaviour as the URLPathVersioning variant, which makes it impossible toreverse
a view that doesn't have versioning.With this change a copy of kwargs is created instead.
I ran
tox
didn't see any new issues caused by my changes.