From db46dbb446a69761b7af58446739ec6322be3d52 Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Tue, 1 Aug 2017 11:40:55 +0200 Subject: [PATCH] Also introduce a new exception type for invalid database IDs (cherry picked from commit 4835cd244ee371ed6f719c4c33925f92a54def16) --- polymorphic/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/polymorphic/models.py b/polymorphic/models.py index 4759d0a..3e4013b 100644 --- a/polymorphic/models.py +++ b/polymorphic/models.py @@ -21,6 +21,10 @@ class PolymorphicTypeUndefined(LookupError): pass +class PolymorphicTypeInvalid(RuntimeError): + pass + + class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)): """ Abstract base class that provides polymorphic behaviour @@ -105,7 +109,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)): if model is not None \ and not issubclass(model, self.__class__) \ and not issubclass(model, self.__class__._meta.proxy_for_model): - raise RuntimeError("ContentType {0} for {1} #{2} does not point to a subclass!".format( + raise PolymorphicTypeInvalid("ContentType {0} for {1} #{2} does not point to a subclass!".format( self.polymorphic_ctype_id, model, self.pk, )) return model