summaryrefslogtreecommitdiff
path: root/django/db/models/utils.py
diff options
context:
space:
mode:
authorAlex Hill <alex@hill.net.au>2016-05-18 23:18:40 +0800
committerTim Graham <timograham@gmail.com>2016-05-19 21:33:36 -0400
commit2ff7ef15b0a1d41e3f121e96cb72a383863046c0 (patch)
treeaebb17708c121fc4acf3611f9d23c69ccdc3dc7c /django/db/models/utils.py
parent0eac5535f7afd2295b1db978dffb97d79030807e (diff)
Refs #26421 -- Refactored Apps.lazy_model_operation() for better checks and tests
Diffstat (limited to 'django/db/models/utils.py')
-rw-r--r--django/db/models/utils.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/django/db/models/utils.py b/django/db/models/utils.py
index f696e30ce2..cda96277a6 100644
--- a/django/db/models/utils.py
+++ b/django/db/models/utils.py
@@ -7,12 +7,18 @@ def make_model_tuple(model):
corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
it's assumed to be a valid model tuple already and returned unchanged.
"""
- if isinstance(model, tuple):
- model_tuple = model
- elif isinstance(model, six.string_types):
- app_label, model_name = model.split(".")
- model_tuple = app_label, model_name.lower()
- else:
- model_tuple = model._meta.app_label, model._meta.model_name
- assert len(model_tuple) == 2, "Invalid model representation: %s" % model
- return model_tuple
+ try:
+ if isinstance(model, tuple):
+ model_tuple = model
+ elif isinstance(model, six.string_types):
+ app_label, model_name = model.split(".")
+ model_tuple = app_label, model_name.lower()
+ else:
+ model_tuple = model._meta.app_label, model._meta.model_name
+ assert len(model_tuple) == 2
+ return model_tuple
+ except (ValueError, AssertionError):
+ raise ValueError(
+ "Invalid model reference '%s'. String model references "
+ "must be of the form 'app_label.ModelName'." % model
+ )