diff --git a/data/model/tag.py b/data/model/tag.py index e22156dbf..f7aa6d5d8 100644 --- a/data/model/tag.py +++ b/data/model/tag.py @@ -727,30 +727,24 @@ def get_possibly_expired_tag(namespace, repo_name, tag_name): Namespace.username == namespace)).get() def associate_generated_tag_manifest_with_tag(tag, manifest, storage_id_map): - try: - manifest = TagManifest.get(digest=manifest.digest) - manifest.tag = tag - manifest.save() - return manifest, False - except TagManifest.DoesNotExist: - oci_manifest = _populate_manifest_and_blobs(tag.repository, manifest, storage_id_map) + oci_manifest = _populate_manifest_and_blobs(tag.repository, manifest, storage_id_map) - with db_transaction(): - try: - (Tag - .select() - .join(TagToRepositoryTag) - .where(TagToRepositoryTag.repository_tag == tag)).get() - except Tag.DoesNotExist: - oci_tag = Tag.create(repository=tag.repository, manifest=oci_manifest, name=tag.name, - reversion=tag.reversion, - lifetime_start_ms=tag.lifetime_start_ts * 1000, - lifetime_end_ms=(tag.lifetime_end_ts * 1000 - if tag.lifetime_end_ts else None), - tag_kind=Tag.tag_kind.get_id('tag')) - TagToRepositoryTag.create(tag=oci_tag, repository_tag=tag, repository=tag.repository) + with db_transaction(): + try: + (Tag + .select() + .join(TagToRepositoryTag) + .where(TagToRepositoryTag.repository_tag == tag)).get() + except Tag.DoesNotExist: + oci_tag = Tag.create(repository=tag.repository, manifest=oci_manifest, name=tag.name, + reversion=tag.reversion, + lifetime_start_ms=tag.lifetime_start_ts * 1000, + lifetime_end_ms=(tag.lifetime_end_ts * 1000 + if tag.lifetime_end_ts else None), + tag_kind=Tag.tag_kind.get_id('tag')) + TagToRepositoryTag.create(tag=oci_tag, repository_tag=tag, repository=tag.repository) - return _associate_manifest(tag, oci_manifest), True + return _associate_manifest(tag, oci_manifest) def _associate_manifest(tag, oci_manifest): diff --git a/data/registry_model/registry_pre_oci_model.py b/data/registry_model/registry_pre_oci_model.py index b73085efa..db4b53ecb 100644 --- a/data/registry_model/registry_pre_oci_model.py +++ b/data/registry_model/registry_pre_oci_model.py @@ -482,8 +482,8 @@ class PreOCIModel(SharedModel, RegistryDataInterface): blob_query = self._lookup_repo_storages_by_content_checksum(repo, manifest.checksums) storage_map = {blob.content_checksum: blob.id for blob in blob_query} try: - tag_manifest, _ = model.tag.associate_generated_tag_manifest_with_tag(tag_obj, manifest, - storage_map) + tag_manifest = model.tag.associate_generated_tag_manifest_with_tag(tag_obj, manifest, + storage_map) assert tag_manifest except IntegrityError: tag_manifest = model.tag.get_tag_manifest(tag_obj)