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

Use Default Version in URLPathVersioning if 'version' Didn't Specified by Client #6380

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rest_framework/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ class URLPathVersioning(BaseVersioning):
invalid_version_message = _('Invalid version in URL path.')

def determine_version(self, request, *args, **kwargs):
"""
Use Default Version If 'version' Did Not Sets by Client in URL (So, It's Equal to None).
e.g:
api/users/ > Use Default Version (As Often The Default Version Is The Latest One).
api/v1/users/ > Check 'v1' Is Allowed?
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On blanance I think the intent of the function is clearer from the code itself than it would be from adding this docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right, it's unnecessary.

version = kwargs.get(self.version_param, self.default_version)

if version is None:
version = self.default_version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be marginally cleaner as:

version = kwargs.get(self.version_param)
if version is None:
    version = self.default_version

Note that we're already checking for "version not in the regex groups", but we're not checking for "version is in the regex groups, but is None".


if not self.is_allowed_version(version):
raise exceptions.NotFound(self.invalid_version_message)
return version
Expand Down