Django

Code

Ticket #1662 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

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

Reported by: russellm Assigned to: russellm
Milestone: Component: Database wrapper
Version: magic-removal Keywords:
Cc: mir@noris.de, justinarthur@ieee.org Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Michael Radziej <mir@noris.de> 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):
   wenga=ForeignKey("Wenga")

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 "./manage.py", line 11, in ?
    execute_manager(settings)
  File "/opt/local/lib/python2.4/site-packages/django/core/management.py", line 1226, in execute_manager
    execute_from_command_line(action_mapping)
  File "/opt/local/lib/python2.4/site-packages/django/core/management.py", line 1152, in execute_from_command_line
    action_mapping[action]()
  File "/opt/local/lib/python2.4/site-packages/django/core/management.py", line 420, in syncdb
    _check_for_validation_errors()
  File "/opt/local/lib/python2.4/site-packages/django/core/management.py", line 956, in _check_for_validation_errors
    num_errors = get_validation_errors(s, app)
  File "/opt/local/lib/python2.4/site-packages/django/core/management.py", 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/options.py", line 121, in get_all_related_objects
    if f.rel and self == f.rel.to._meta:
AttributeError: 'str' object has no attribute '_meta'

Attachments

Change History

04/23/06 17:14:29 changed by mir@noris.de

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.

04/23/06 17:18:01 changed by adrian

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

06/22/06 23:37:00 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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.

10/24/06 15:17:23 changed by adrian

  • milestone deleted.

Milestone Version 0.92 deleted

07/12/07 11:37:34 changed by justinarthu@ieee.org

  • cc changed from mir@noris.de to mir@noris.de, justinarthur@ieee.org.
  • status changed from closed to reopened.
  • resolution deleted.

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

07/12/07 12:16:34 changed by justinarthur@ieee.org

  • status changed from reopened to closed.
  • resolution set to fixed.

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.


Add/Change #1662 ('string' form references in models don't appear to work)




Change Properties
Action