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 edge case w/ identical canonical versions #3822

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions tests/unit/packaging/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def test_traversal_cant_find(self, db_request):
with pytest.raises(KeyError):
project["1.0"]

def test_traversal_cant_find_if_multiple(self, db_request):
project = DBProjectFactory.create()
DBReleaseFactory.create(version='1.0.0', project=project)
DBReleaseFactory.create(version='1.0', project=project)

with pytest.raises(KeyError):
project["1"]

def test_doc_url_doesnt_exist(self, db_request):
project = DBProjectFactory.create()
assert project.documentation_url is None
Expand Down
19 changes: 13 additions & 6 deletions warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,20 @@ def __getitem__(self, version):
# There are multiple releases of this project which have the same
# canonical version that were uploaded before we checked for
# canonical version equivalence, so return the exact match instead
return (
session.query(Release)
.filter(
(Release.project == self) & (Release.version == version)
try:
return (
session.query(Release)
.filter(
(Release.project == self) &
(Release.version == version)
)
.one()
)
.one()
)
except NoResultFound:
# There are multiple releases of this project which have the
# same canonical version, but none that have the exact version
# specified, so just 404
raise KeyError from None
except NoResultFound:
raise KeyError from None

Expand Down