Opened 18 years ago
Closed 17 years ago
#3323 closed (fixed)
Unhelpful error message in case of unresolved string relation ('str' object has no attribute '_meta')
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | sprintsept14 sprintdec01 | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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 (4)
Change History (13)
by , 18 years ago
Attachment: | django-string-rel.patch added |
---|
comment:1 by , 18 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Thanks Alex for reporting the issue and providing a starting patch.
by , 17 years ago
Attachment: | django.db.models.options.rev6263.diff added |
---|
similar hackish fix for ManyToManyField
comment:4 by , 17 years ago
Keywords: | sprintsept14 added |
---|---|
Needs tests: | set |
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.
comment:5 by , 17 years ago
Patch needs improvement: | unset |
---|
Added a patch wich fixes this without (hopefully) being hackish.
Validation error will be given now as intended - crash with traceback is gone now.
by , 17 years ago
Attachment: | patch-foreignkey-attributeerror.diff added |
---|
Patch updated: fixed the error message to display the correct name of missing model
by , 17 years ago
Attachment: | django-string-rel-with-test.patch added |
---|
update to the recent patch, adds tests keeps the behavior consistent
comment:7 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 17 years ago
Summary: | Unhelpful error message in case of unresolved string relation → Unhelpful error message in case of unresolved string relation ('str' object has no attribute '_meta') |
---|
quick hack