Skip to content

Commit

Permalink
Make Release.from_tags() more predictable
Browse files Browse the repository at this point in the history
If Release.from_tags() was called with a tag not associated with any
release, it would raise KeyError (unless an earlier tag in the list
was found first.) This was unexpected from the documentation - and was
handled by one caller but not others. Change it to return None in
this case - this was handled by all callers.

Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
  • Loading branch information
owtaylor authored and mergify[bot] committed Aug 16, 2018
1 parent 0ba628a commit 78dd4aa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 2 additions & 0 deletions bodhi/server/models.py
Expand Up @@ -947,6 +947,8 @@ def from_tags(cls, tags, session):
"""
tag_types, tag_rels = cls.get_tags(session)
for tag in tags:
if tag not in tag_rels:
continue
release = session.query(cls).filter_by(name=tag_rels[tag]).first()
if release:
return release
Expand Down
9 changes: 1 addition & 8 deletions bodhi/server/validators.py
Expand Up @@ -155,14 +155,7 @@ def cache_release(request, build):
tags = cache_tags(request, build)
if tags is None:
return None
build_rel = None
try:
build_rel = Release.from_tags(tags, request.db)
except KeyError:
log.warn('Unable to determine release from '
'tags: %r build: %r' % (tags, build))
request.errors.add('body', 'builds',
'Unable to determine release from build: %s' % build)
build_rel = Release.from_tags(tags, request.db)
if not build_rel:
msg = 'Cannot find release associated with ' + \
'build: {}, tags: {}'.format(build, tags)
Expand Down
2 changes: 0 additions & 2 deletions bodhi/tests/server/services/test_updates.py
Expand Up @@ -872,8 +872,6 @@ def test_edit_add_build_from_different_release(self):
expected_json = {
u'status': u'error',
u'errors': [
{u'description': u'Unable to determine release from build: bodhi-3.2.0-1.fc27',
u'location': u'body', u'name': u'builds'},
{u'description': (
u"Cannot find release associated with build: bodhi-3.2.0-1.fc27, "
u"tags: [u'f27-updates-candidate', u'f27', u'f27-updates-testing']"),
Expand Down

0 comments on commit 78dd4aa

Please sign in to comment.