Opened 14 years ago

Closed 13 years ago

#1662 closed defect (fixed)

'string' form references in models don't appear to work

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Database layer (models, ORM) Version: magic-removal
Severity: normal Keywords:
Cc: mir@…, justinarthur@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Michael Radziej <mir@…> reports that the following two models, which use the 'string' form of model reference in Foreign Keys, fail:

Version 1 (back referenced model):

class Wenga(models.Moldel):

class Benga(models.Model):
   wenga = ForeignKey("Wenga")

Version 2: Forward referenced model

class Benga(models.Model):

class Wenga(models.Model):

Version 2 succeeds syncdb, but fails on model import. Version 1 fails on syncdb with the same error that Version 2 provides during syncdb:

Traceback (most recent call last):
  File "./", line 11, in ?
  File "/opt/local/lib/python2.4/site-packages/django/core/", line 1226, in execute_manager
  File "/opt/local/lib/python2.4/site-packages/django/core/", line 1152, in execute_from_command_line
  File "/opt/local/lib/python2.4/site-packages/django/core/", line 420, in syncdb
  File "/opt/local/lib/python2.4/site-packages/django/core/", line 956, in _check_for_validation_errors
    num_errors = get_validation_errors(s, app)
  File "/opt/local/lib/python2.4/site-packages/django/core/", line 851, in get_validation_errors
    for r in rel_opts.get_all_related_objects():
  File "/opt/local/lib/python2.4/site-packages/django/db/models/", line 121, in get_all_related_objects
    if f.rel and self ==
AttributeError: 'str' object has no attribute '_meta'

Change History (6)

comment:1 Changed 14 years ago by mir@…

Hmm ... seems ticket #167 is about the same. Now, which one should be closed as duplicate? Other ticket has more information, this one is assigned to an earlier milestone. Russell?

Also, I'm really afraid there's too much to do for this to really make it into 0.92. See the dicussion in the other ticket.

comment:2 Changed 14 years ago by Adrian Holovaty

I'm closing #167 as a duplicate, because this one is more up-to-date.

comment:3 Changed 14 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [3195]) Fixed #1662 -- Added resolver for string-form model references for models that have already been loaded, with tests to validate both forward and backward referenced model names. Light refactoring of model loading to make regression tests behave more like normal model loading. Also clarifies the text of some validation errors.

comment:4 Changed 14 years ago by Adrian Holovaty

milestone: Version 0.92

Milestone Version 0.92 deleted

comment:5 Changed 13 years ago by justinarthu@…

Cc: justinarthur@… added
Resolution: fixed
Status: closedreopened

I'm able to reproduce this in [5677].

comment:6 Changed 13 years ago by justinarthur@…

Resolution: fixed
Status: reopenedclosed

Actually, this is only reproducible for me if the string-referenced model is defined in another app of the same project. I'll split that into an enhancement request. Re-marking as fixed.

Note: See TracTickets for help on using tickets.
Back to Top