#16299: Django model-module doesn't support unicode_literals
-------------------------------------+-------------------------------------
 Reporter:  martijn.bastiaan@…       |          Owner:  nobody
     Type:  Bug                      |         Status:  new
Milestone:                           |      Component:  Database layer
  Version:  SVN                      |  (models, ORM)
 Keywords:  unicode, ForeignKey,     |       Severity:  Normal
  AttributeError                     |   Triage Stage:  Unreviewed
Has patch:  1                        |  Easy pickings:  1
    UI/UX:  0                        |
-------------------------------------+-------------------------------------
 Hello all,

 When using
 {{{
 from __future__ import unicode_literals
 }}}
 in a model file, Django fails to recognize a model referenced by a string
 and raises a quite obscure error message:
 {{{
 Traceback (most recent call last):
   File "test.py", line 5, in <module>
     a = article.Article.objects.get(id=57220255)
   File "/usr/local/lib/django/django/db/models/manager.py", line 132, in
 get
     return self.get_query_set().get(*args, **kwargs)
   File "/usr/local/lib/django/django/db/models/query.py", line 341, in get
     clone = self.filter(*args, **kwargs)
   File "/usr/local/lib/django/django/db/models/query.py", line 550, in
 filter
     return self._filter_or_exclude(False, *args, **kwargs)
   File "/usr/local/lib/django/django/db/models/query.py", line 568, in
 _filter_or_exclude
     clone.query.add_q(Q(*args, **kwargs))
   File "/usr/local/lib/django/django/db/models/sql/query.py", line 1172,
 in add_q
     can_reuse=used_aliases, force_having=force_having)
   File "/usr/local/lib/django/django/db/models/sql/query.py", line 1060,
 in add_filter
     negate=negate, process_extras=process_extras)
   File "/usr/local/lib/django/django/db/models/sql/query.py", line 1226,
 in setup_joins
     field, model, direct, m2m = opts.get_field_by_name(name)
   File "/usr/local/lib/django/django/db/models/options.py", line 307, in
 get_field_by_name
     cache = self.init_name_map()
   File "/usr/local/lib/django/django/db/models/options.py", line 339, in
 init_name_map
     for f, model in self.get_all_related_objects_with_model():
   File "/usr/local/lib/django/django/db/models/options.py", line 371, in
 get_all_related_objects_with_model
     self._fill_related_objects_cache()
   File "/usr/local/lib/django/django/db/models/options.py", line 393, in
 _fill_related_objects_cache
     if f.rel and not isinstance(f.rel.to, str) and self == f.rel.to._meta:
 AttributeError: 'unicode' object has no attribute '_meta'
 }}}

 Model example:
 {{{
     insert_user = models.ForeignKey("models.User",
 db_column='insertuser_id')

     # Or without from __future__ import unicode_literals
     insert_user = models.ForeignKey(u"models.User",
 db_column='insertuser_id')
 }}}

 I've attached a patch.

 Yours,
 Martijn

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16299>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to