Skip to content

Commit

Permalink
Add additional content type verification to RepositoryVersion
Browse files Browse the repository at this point in the history
re: #5701
https://pulp.plan.io/issues/5701
(cherry picked from commit 0604a7b)
  • Loading branch information
dralley authored and bmbouter committed Dec 11, 2019
1 parent 9077c5a commit 6b2af56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pulpcore/app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,18 @@ def save(self, *args, **kwargs):
# Prepend the TYPE defined on a detail model with a django app label.
# If a plugin sets the type field themselves, it's used as-is.
if not self.pulp_type:
self.pulp_type = '{app_label}.{type}'.format(app_label=self._meta.app_label,
type=self.TYPE)
self.pulp_type = self.get_pulp_type()
return super().save(*args, **kwargs)

@classmethod
def get_pulp_type(cls):
""" Get the "pulp_type" string associated with this MasterModel type.
"""
return '{app_label}.{type}'.format(
app_label=cls._meta.app_label,
type=cls.TYPE
)

def cast(self):
"""Return a "Detail" model instance of this master-detail pair.
Expand Down
16 changes: 15 additions & 1 deletion pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,25 @@ def __exit__(self, exc_type, exc_value, traceback):
self.delete()
else:
try:
self.repository.finalize_new_version(self)
repository = self.repository.cast()
repository.finalize_new_version(self)
no_change = not self.added() and not self.removed()
if no_change:
self.delete()
else:
content_types_seen = set(
self.content.values_list('pulp_type', flat=True).distinct()
)
content_types_supported = set(
ctype.get_pulp_type() for ctype in repository.CONTENT_TYPES
)

unsupported_types = content_types_seen - content_types_supported
if unsupported_types:
raise ValueError(
"Saw unsupported content types {}".format(unsupported_types)
)

self.complete = True
self.save()
self._compute_counts()
Expand Down

0 comments on commit 6b2af56

Please sign in to comment.