Fix recursion error in images API

We only need parents for the root set of images
This commit is contained in:
Joseph Schorr 2017-08-09 13:27:54 -04:00
parent 8ff8a4ca1a
commit 2184721d28

View file

@ -3,11 +3,14 @@ from data import model
from endpoints.api.image_models_interface import (ImageInterface, ImageWithHistory, ImageWithTags,
Image)
def _image(namespace_name, repo_name, image, all_images):
parent_images = [all_images[ancestor_id] for ancestor_id in image.ancestor_id_list()
if all_images.get(ancestor_id)]
parent_image_tuples = [_image(namespace_name, repo_name, parent_image, all_images)
for parent_image in parent_images]
def _image(namespace_name, repo_name, image, all_images, include_parents=True):
parent_image_tuples = []
if include_parents:
parent_images = [all_images[ancestor_id] for ancestor_id in image.ancestor_id_list()
if all_images.get(ancestor_id)]
parent_image_tuples = [_image(namespace_name, repo_name, parent_image, all_images, False)
for parent_image in parent_images]
return Image(image.docker_image_id, image.created, image.comment, image.command,
image.storage.image_size, image.storage.uploading, parent_image_tuples)
@ -28,7 +31,8 @@ class PreOCIModel(ImageInterface):
all_images = model.image.get_repository_images_without_placements(repo)
all_images_map = {image.id: image for image in all_images}
all_tags = model.tag.list_repository_tags(namespace_name, repo_name)
all_tags = list(model.tag.list_repository_tags(namespace_name, repo_name))
tags_by_docker_id = defaultdict(list)
for tag in all_tags:
tags_by_docker_id[tag.image.docker_image_id].append(tag)