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 <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-03-01 10:37:49 +13:00
parent 97a6b7eaf9
commit 4ea3834033

View File

@ -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