Handle IntegrityError in tag update code

Fixes https://sentry.io/coreos/backend-production/issues/173470565/events/4938537230/
This commit is contained in:
Joseph Schorr 2017-02-21 12:51:39 -05:00
parent 9db20ff961
commit d29d2da1ca
2 changed files with 7 additions and 1 deletions

View file

@ -96,6 +96,9 @@ class ServiceNameInvalid(DataModelException):
class TagAlreadyCreatedException(DataModelException):
pass
class StaleTagException(DataModelException):
pass
class TooManyLoginAttemptsException(Exception):
def __init__(self, message, retry_after):

View file

@ -4,7 +4,7 @@ from uuid import uuid4
from peewee import IntegrityError
from data.model import (image, db_transaction, DataModelException, _basequery,
InvalidManifestException, TagAlreadyCreatedException)
InvalidManifestException, TagAlreadyCreatedException, StaleTagException)
from data.database import (RepositoryTag, Repository, Image, ImageStorage, Namespace, TagManifest,
RepositoryNotification, Label, TagManifestLabel, get_epoch_timestamp,
db_for_update)
@ -92,6 +92,9 @@ def create_or_update_tag(namespace_name, repository_name, tag_name, tag_docker_i
tag.save()
except RepositoryTag.DoesNotExist:
pass
except IntegrityError:
msg = 'Tag with name %s was stale when we tried to update it; Please retry the push'
raise StaleTagException(msg % tag_name)
try:
image_obj = Image.get(Image.docker_image_id == tag_docker_image_id, Image.repository == repo)