#11116 closed (fixed)
delete() triggers an error on proxy model instances
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | proxy, model, delete | |
Cc: | andy@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
>>> from hit.vote.models import VoteProxy >>> inst = VoteProxy.objects.get(pk=2) >>> inst.delete() ------------------------------------------------------------ Traceback (most recent call last): File "<ipython console>", line 1, in <module> File "/home/sam/projects/djangotrunk-env/lib/python2.5/site-packages/django/db/models/base.py", line 557, in delete self._collect_sub_objects(seen_objs) File "/home/sam/projects/djangotrunk-env/lib/python2.5/site-packages/django/db/models/base.py", line 544, in _collect_sub_objects parent_obj = getattr(self, link.name) AttributeError: 'NoneType' object has no attribute 'name'
The problem is in django/db/models/base.py
http://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L151
151 elif not is_proxy: 152 attr_name = '%s_ptr' % base._meta.module_name 153 field = OneToOneField(base, name=attr_name, 154 auto_created=True, parent_link=True) 155 new_class.add_to_class(attr_name, field) 156 else: 157 field = None 158 new_class._meta.parents[base] = field
>>> inst._meta.parents {<class 'voting.models.Vote'>: None}
http://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L541
541 parent_stack = self._meta.parents.values() 542 while parent_stack: 543 link = parent_stack.pop() 544 parent_obj = getattr(self, link.name)
>>> inst._meta.parents.values() [None]
Attachments (3)
Change History (14)
comment:1 by , 15 years ago
Version: | 1.0 → SVN |
---|
comment:2 by , 15 years ago
comment:3 by , 15 years ago
Has patch: | set |
---|
by , 15 years ago
Attachment: | 11116_proxy_model_delete2.diff added |
---|
Filtering parent.values() for True objects
follow-up: 5 comment:4 by , 15 years ago
With 11116_proxy_model_delete2.diff:
Ran 829 tests in 388.585s
OK
comment:5 by , 15 years ago
milestone: | → 1.1 |
---|---|
Needs tests: | set |
Replying to samueladam
That's good the current tests pass, what about a test that shows the failure and shows that the patch fixes it? Neither patch has that, so far as I can see.
Setting 1.1 milestone since someone with a clue in this area of the code should probably look at this for 1.1.
comment:6 by , 15 years ago
Needs tests: | unset |
---|
@kmtracey
There you go for the test
@pmclanahan
Fox a fix with an "if", those are more pythonic:
if link: pass #or if hasattr(link, 'name'): pass
comment:7 by , 15 years ago
@samueladam
I agree. And I had that first, but then I thought about the fact that I was trying to correct for a specific condition where the value was set to None, and since I wasn't absolutely sure of the truth of typical values, I decided to be explicit, which I considered to be in keeping w/ the zen. But if expected values always evaluate to true, then you're right.
In any case, as long as we can get this fixed and checked in, I'll be happy. Thanks for the help!
comment:8 by , 15 years ago
Test fails w/ old code, passes with the new. Looks perfect. Thanks samueladam!
comment:9 by , 15 years ago
Cc: | added |
---|
comment:10 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'm having this exact problem. Bump.