diff --git a/data/model/__init__.py b/data/model/__init__.py index 331b2f0b3..09521f9e4 100644 --- a/data/model/__init__.py +++ b/data/model/__init__.py @@ -96,6 +96,9 @@ class ServiceNameInvalid(DataModelException): class TagAlreadyCreatedException(DataModelException): pass +class StaleTagException(DataModelException): + pass + class TooManyLoginAttemptsException(Exception): def __init__(self, message, retry_after): diff --git a/data/model/tag.py b/data/model/tag.py index e5c3b3233..239bc3468 100644 --- a/data/model/tag.py +++ b/data/model/tag.py @@ -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)