From 0035a1ec6d8d20de8f1cfa5a9e38e6fce057f86a Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 21 Jan 2019 16:42:24 -0500 Subject: [PATCH] Fix a bug in manifest backfill that made it only work on active tags --- data/model/tag.py | 6 ++---- data/registry_model/registry_pre_oci_model.py | 4 ++-- data/registry_model/test/test_interface.py | 5 +++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/data/model/tag.py b/data/model/tag.py index db9a3e9f1..345a0a391 100644 --- a/data/model/tag.py +++ b/data/model/tag.py @@ -726,9 +726,7 @@ def get_possibly_expired_tag(namespace, repo_name, tag_name): .where(RepositoryTag.name == tag_name, Repository.name == repo_name, Namespace.username == namespace)).get() - -def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest, storage_id_map): - tag = get_active_tag(namespace, repo_name, tag_name) +def associate_generated_tag_manifest_with_tag(tag, manifest, storage_id_map): try: manifest = TagManifest.get(digest=manifest.digest) manifest.tag = tag @@ -744,7 +742,7 @@ def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest, s .join(TagToRepositoryTag) .where(TagToRepositoryTag.repository_tag == tag)).get() except Tag.DoesNotExist: - oci_tag = Tag.create(repository=tag.repository, manifest=oci_manifest, name=tag_name, + 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 diff --git a/data/registry_model/registry_pre_oci_model.py b/data/registry_model/registry_pre_oci_model.py index 747f2d928..637aa5f98 100644 --- a/data/registry_model/registry_pre_oci_model.py +++ b/data/registry_model/registry_pre_oci_model.py @@ -483,8 +483,8 @@ class PreOCIModel(SharedModel, RegistryDataInterface): storage_map = {blob.content_checksum: blob.id for blob in blob_query} try: - tag_manifest, _ = model.tag.associate_generated_tag_manifest(namespace_name, repo_name, - tag.name, 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) diff --git a/data/registry_model/test/test_interface.py b/data/registry_model/test/test_interface.py index 4a61beb5f..5eb0e2d38 100644 --- a/data/registry_model/test/test_interface.py +++ b/data/registry_model/test/test_interface.py @@ -435,14 +435,15 @@ def clear_rows(initialized_db): ]) def test_backfill_manifest_for_tag(repo_namespace, repo_name, clear_rows, pre_oci_model): repository_ref = pre_oci_model.lookup_repository(repo_namespace, repo_name) - tags = pre_oci_model.list_repository_tags(repository_ref) + tags, has_more = pre_oci_model.list_repository_tag_history(repository_ref, size=2500) assert tags + assert not has_more for tag in tags: assert not tag.manifest_digest assert pre_oci_model.backfill_manifest_for_tag(tag) - tags = pre_oci_model.list_repository_tags(repository_ref, include_legacy_images=True) + tags, _ = pre_oci_model.list_repository_tag_history(repository_ref) assert tags for tag in tags: assert tag.manifest_digest