From 3f54007a0435ab6ec7d933a987d953981e5538a5 Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Thu, 10 Jan 2019 11:33:05 -0500 Subject: [PATCH] Fix migration for cases in which no vendor field is provided Fixes an error when the primary.xml.gz metadata doesn't provide a vendor field. closes #4309 https://pulp.plan.io/issues/4309 --- .../pulp_rpm/plugins/migrations/0045_populate_vendor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/pulp_rpm/plugins/migrations/0045_populate_vendor.py b/plugins/pulp_rpm/plugins/migrations/0045_populate_vendor.py index fb7bece64..703cef3ec 100644 --- a/plugins/pulp_rpm/plugins/migrations/0045_populate_vendor.py +++ b/plugins/pulp_rpm/plugins/migrations/0045_populate_vendor.py @@ -37,10 +37,12 @@ def migrate_rpm(collection, unit): primary_xml = _HEADER.format(gzip.zlib.decompress(primary_xml)) root_element = ET.fromstring(primary_xml) delta = {} - delta['vendor'] = root_element.find( + vendor_element = root_element.find( './common:package/common:format/rpm:vendor', _NAMESPACES - ).text - collection.update_one({'_id': unit['_id']}, {'$set': delta}) + ) + if vendor_element: + delta['vendor'] = vendor_element.text + collection.update_one({'_id': unit['_id']}, {'$set': delta}) def migrate(*args, **kwargs):