Skip to content

Commit

Permalink
Respect search criteria in the erratum serializer
Browse files Browse the repository at this point in the history
Serializer should not add a pkglist to an erratum if it was excluded from
fields in search criteria.
Serializer handles the case when errata_id is absent in fields in search
criteria while pkglist is not.

re #3172
https://pulp.plan.io/issues/3172

(cherry picked from commit a679f26)
  • Loading branch information
goosemania authored and pcreech committed Jun 18, 2018
1 parent a23253e commit 8456d13
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions plugins/pulp_rpm/plugins/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,36 @@ def serialize(self, unit):
"""
Convert a single unit to it's dictionary form.
Add to errratum unit its pkglist.
Add to errratum unit its pkglist if needed.
Duplicated pkglists are eliminated.
:param unit: The object to be converted
:type unit: object
"""
from pulp_rpm.plugins.db import models

pkglists = models.Errata.get_unique_pkglists(unit.get('errata_id'))
unit['pkglist'] = []
coll_num = 0
for pkglist in pkglists:
for coll in pkglist:
# To preserve the original format of a pkglist the 'short' and 'name'
# keys are added. 'short' can be an empty string, collection 'name'
# should be unique within an erratum.
unit['pkglist'].append({'packages': coll,
'short': '',
'name': 'collection-%s' % coll_num})
coll_num += 1
# If pkglist field is absent, it's on purpose, e.g. not specified in the fields during
# search. So it should not be added during serialization.
# If pkglist field is present, it's always emtpy => it should be filled in.
if 'pkglist' in unit:
errata_id = unit.get('errata_id')

# If fields in search criteria don't include errata_id
if errata_id is None:
erratum_obj = models.Errata.objects.only('errata_id').get(id=unit.get('_id'))
errata_id = erratum_obj.errata_id

pkglists = models.Errata.get_unique_pkglists(errata_id)
coll_num = 0
for pkglist in pkglists:
for coll in pkglist:
# To preserve the original format of a pkglist the 'short' and 'name'
# keys are added. 'short' can be an empty string, collection 'name'
# should be unique within an erratum.
unit['pkglist'].append({'packages': coll,
'short': '',
'name': 'collection-%s' % coll_num})
coll_num += 1

return super(Errata, self).serialize(unit)

Expand Down

0 comments on commit 8456d13

Please sign in to comment.