Django

Code

Ticket #3323 (closed: fixed)

Opened 1 year ago

Last modified 6 months ago

Unhelpful error message in case of unresolved string relation ('str' object has no attribute '_meta')

Reported by: alex@gc-web.de Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: sprintsept14 sprintdec01 Cc:
Triage Stage: Ready for checkin Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

imagine the following model:

class Test(models.model):
   rel = models.ForeignKey("bleh")

if the relation is not resolvable, in case of a typo or if it's in a different file, the user gets a rather unhelpful exception:

Unhandled exception in thread started by <function inner_run at 0x2af9aa4e9668>
Traceback (most recent call last):
  File "/home/alex/source/svn/django/django/core/management.py", line 1108, in inner_run
    validate()
  File "/home/alex/source/svn/django/django/core/management.py", line 1070, in validate
    num_errors = get_validation_errors(outfile)
  File "/home/alex/source/svn/django/django/core/management.py", line 936, in get_validation_errors
    for r in rel_opts.get_all_related_objects():
  File "/home/alex/source/svn/django/django/db/models/options.py", line 127, in get_all_related_objects
    if f.rel and self == f.rel.to._meta:
AttributeError: 'str' object has no attribute '_meta'

a quick hacky fix is attached, but i guess it should be done in django.core.management.validate

Attachments

django-string-rel.patch (0.7 kB) - added by alex@gc-web.de on 01/18/07 13:07:57.
quick hack
django.db.models.options.rev6263.diff (0.7 kB) - added by Axis_of_Entropy on 09/15/07 00:33:48.
similar hackish fix for ManyToManyField?
patch-foreignkey-attributeerror.diff (2.9 kB) - added by Gregor_Kopka on 09/30/07 11:47:38.
Patch updated: fixed the error message to display the correct name of missing model
django-string-rel-with-test.patch (4.7 kB) - added by shaleh on 11/30/07 18:38:00.
update to the recent patch, adds tests keeps the behavior consistent

Change History

01/18/07 13:07:57 changed by alex@gc-web.de

  • attachment django-string-rel.patch added.

quick hack

01/18/07 13:08:29 changed by anonymous

  • needs_better_patch set to 1.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

01/18/07 14:20:06 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

Thanks Alex for reporting the issue and providing a starting patch.

07/12/07 11:42:42 changed by anonymous

This might be related if not a duplicate of #1662.

09/15/07 00:33:48 changed by Axis_of_Entropy

  • attachment django.db.models.options.rev6263.diff added.

similar hackish fix for ManyToManyField?

09/15/07 00:35:37 changed by Axis_of_Entropy

  • keywords set to sprintsept14.
  • needs_tests set to 1.

I've also encountered this, but with ManyToManyField?, and I think that this may describe the root problem of #5311 (see my discussion there)
I've attached a hackish fix that helped my problem.

09/30/07 11:11:17 changed by Gregor_Kopka

  • needs_better_patch deleted.

Added a patch wich fixes this without (hopefully) being hackish. Validation error will be given now as intended - crash with traceback is gone now.

09/30/07 11:47:38 changed by Gregor_Kopka

  • attachment patch-foreignkey-attributeerror.diff added.

Patch updated: fixed the error message to display the correct name of missing model

11/30/07 18:38:00 changed by shaleh

  • attachment django-string-rel-with-test.patch added.

update to the recent patch, adds tests keeps the behavior consistent

11/30/07 21:52:53 changed by shaleh

  • keywords changed from sprintsept14 to sprintsept14 sprintdec01.
  • needs_tests deleted.

my patch adds tests

12/01/07 22:10:18 changed by Simon G <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

12/01/07 22:10:35 changed by Simon G <dev@simon.net.nz>

  • summary changed from Unhelpful error message in case of unresolved string relation to Unhelpful error message in case of unresolved string relation ('str' object has no attribute '_meta').

12/02/07 17:18:40 changed by mtredinnick

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

Fixed in [6835].


Add/Change #3323 (Unhelpful error message in case of unresolved string relation ('str' object has no attribute '_meta'))




Change Properties
Action