#26977: TypeError: isinstance() arg 2 must be a class, type, or tuple of classes
and types
--------------------------------------+--------------------
     Reporter:  teeberg               |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Uncategorized         |    Version:  1.9
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 Trying to instantiate an abstract model with a foreign key worked without
 throwing any warnings in Django 1.8. In Django 1.9.8, this code:
 {{{
 class UserProfile(Model):
     user = models.ForeignKey('auth.user')
     class Meta(object):
         app_label = 'core'
         abstract = True
 UserProfile()
 }}}
 raises this exception:
 {{{
 Traceback (most recent call last):
   File "<ipython-input-7-5fa4dfdf1ad9>", line 2, in <module>
     UserProfile()
   File ".../.venv/lib/python2.7/site-packages/django/db/models/base.py",
 line 432, in __init__
     val = field.get_default()
   File ".../.venv/lib/python2.7/site-
 packages/django/db/models/fields/related.py", line 905, in get_default
     if isinstance(field_default, self.remote_field.model):
 TypeError: isinstance() arg 2 must be a class, type, or tuple of classes
 and types
 }}}

 While the code mentions that abstract models can not be instantiated [1],
 I couldn't find mention of this in the docs. Abstract models without
 foreign keys can still be instantiated perfectly fine.

 I couldn't find any description of this change in the Release Notes, so
 not sure if I missed it there or if this is maybe an undocumented
 backwards-incompatible change.

 [1]
 
https://github.com/django/django/blob/026574e03c6b6fd20a45f97b0470afb70e41fda4/django/db/models/base.py#L284

--
Ticket URL: <https://code.djangoproject.com/ticket/26977>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.837c929d3f7a335f54dccd2071470f41%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to