From c324ebd7f60a14bfb06cb84e520d1a8b919d1058 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 3 Dec 2015 16:04:17 -0500 Subject: [PATCH] Only write exceptions for manifest gen when a tag exists Fixes #1019 Currently, we just raise an exception to the logs regardless, which can make it appear as if there is an issue (when there isn't). --- data/model/tag.py | 4 ++-- endpoints/v2/manifest.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data/model/tag.py b/data/model/tag.py index afc0b36cb..a392df2fd 100644 --- a/data/model/tag.py +++ b/data/model/tag.py @@ -223,7 +223,7 @@ def store_tag_manifest(namespace, repo_name, tag_name, docker_image_id, manifest return TagManifest.create(tag=tag, digest=manifest_digest, json_data=manifest_data) -def _get_active_tag(namespace, repo_name, tag_name): +def get_active_tag(namespace, repo_name, tag_name): return _tag_alive(RepositoryTag .select() .join(Image) @@ -235,7 +235,7 @@ def _get_active_tag(namespace, repo_name, tag_name): def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest_digest, manifest_data): - tag = _get_active_tag(namespace, repo_name, tag_name) + tag = get_active_tag(namespace, repo_name, tag_name) return TagManifest.create(tag=tag, digest=manifest_digest, json_data=manifest_data) diff --git a/endpoints/v2/manifest.py b/endpoints/v2/manifest.py index c5ceafeac..00b7696aa 100644 --- a/endpoints/v2/manifest.py +++ b/endpoints/v2/manifest.py @@ -17,6 +17,7 @@ from endpoints.trackhelper import track_and_log from endpoints.notificationhelper import spawn_notification from digest import digest_tools from data import model +from data.database import RepositoryTag logger = logging.getLogger(__name__) @@ -217,6 +218,11 @@ def fetch_manifest_by_tagname(namespace, repo_name, manifest_ref): try: manifest = model.tag.load_tag_manifest(namespace, repo_name, manifest_ref) except model.InvalidManifestException: + try: + model.tag.get_active_tag(namespace, repo_name, manifest_ref) + except RepositoryTag.DoesNotExist: + raise ManifestUnknown() + try: manifest = _generate_and_store_manifest(namespace, repo_name, manifest_ref) except model.DataModelException: