Skip to content
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

Merged
merged 4 commits into from
May 18, 2023
Merged

Conversation

jornvanwier
Copy link
Contributor

When using URLPathVersioning reverse adds request.version to the kwargs and tries to find a match. If that fails, it falls back to the default reverse 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 to reverse 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.

@rpkilby
Copy link
Member

rpkilby commented Apr 1, 2020

Hi @jornvanwier. Could you add a test case that demonstrates the failure?

@jornvanwier
Copy link
Contributor Author

jornvanwier commented Apr 2, 2020

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.

@stale
Copy link

stale bot commented Jun 19, 2022

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.

@stale stale bot added the stale label Jun 19, 2022
@stale stale bot closed this Dec 26, 2022
@auvipy auvipy reopened this Dec 26, 2022
@auvipy auvipy removed the stale label Dec 26, 2022
@stale
Copy link

stale bot commented Apr 2, 2023

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.

@stale stale bot added the stale label Apr 2, 2023
@auvipy auvipy removed the stale label Apr 2, 2023
tests/test_versioning.py Outdated Show resolved Hide resolved
@auvipy auvipy requested a review from a team May 17, 2023 14:07
Copy link
Member

@tfranzel tfranzel left a 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.

@auvipy auvipy added this to the 3.15 milestone May 18, 2023
@auvipy auvipy merged commit a25aac7 into encode:master May 18, 2023
saadullahaleem pushed a commit to saadullahaleem/django-rest-framework that referenced this pull request May 27, 2023
* 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]>
auvipy added a commit that referenced this pull request May 29, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants