From 4ea3834033fb502e7e10ff54d883ea9179eac99c Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Thu, 1 Mar 2018 10:37:49 +1300 Subject: [PATCH] rrs_upstream_history: properly handle missing Recipe If the Recipe object doesn't exist here then an exception will be raised rather than None being returned, and this will also trigger if multiple recipes match. This may have never triggered in the past because this would have been run right after updating all the recipes in the layer and clearing out duplicates (which we were doing earlier), and thus what is in the database would match the recipe files in the repository, assuming no errors occurred during parsing). We can't remove duplicates though so we need to switch over to using filter() and taking the first recipe. Signed-off-by: Paul Eggleton --- rrs/tools/rrs_upstream_history.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rrs/tools/rrs_upstream_history.py b/rrs/tools/rrs_upstream_history.py index 6aa5631..f5e0029 100755 --- a/rrs/tools/rrs_upstream_history.py +++ b/rrs/tools/rrs_upstream_history.py @@ -21,6 +21,7 @@ from layerindex import utils utils.setup_django() from django.db import transaction +from django.core.exceptions import ObjectDoesNotExist import settings logger = get_logger("UpstreamHistory", settings) @@ -85,11 +86,12 @@ def get_upstream_info(layerbranch, recipe_data, result): get_recipe_pv_without_srcpv pn = recipe_data.getVar('PN', True) - recipe = Recipe.objects.get(layerbranch=layerbranch, pn=pn) - if not recipe: - logger.info("%s: in layer branch %s not found." % \ + recipes = Recipe.objects.filter(layerbranch=layerbranch, pn=pn) + if not recipes: + logger.warning("%s: in layer branch %s not found." % \ (pn, str(layerbranch))) return + recipe = recipes[0] ru = RecipeUpstream() ru.recipe = recipe