#25890: AUTH_USER_MODEL unfriendly to custom models with more than one level of
encapsulation
--------------------------------------+-----------------------------
     Reporter:  junhua                |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  contrib.auth          |    Version:  1.9
     Severity:  Normal                |   Keywords:  AUTH_USER_MODEL
 Triage Stage:  Unreviewed            |  Has patch:  1
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+-----------------------------
 In db/models/utils.py, when model is a string, it's handled by the
 following:

 `app_label, model_name = model.split(".")`

 In the event if AUTH_USER_MODEL has more than a level of encapsulation
 (e.g. "apps/authn/CustomUser"), it throws a ValueError: too many values to
 unpack.

  Suggested fix:

 {{{
 def make_model_tuple(model):
     """
     Takes a model or a string of the form "app_label.ModelName" and
 returns a
     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):
         strings = model.split(".")
         app_label = ".".join(strings[:-1])
         model_name = strings[-1]
         # 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
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25890>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.70061e948b8c57633d297d08d14b30ac%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to