#14387 closed (invalid)
pre_save problem with inherrited model
Reported by: | iskren | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2 |
Severity: | Keywords: | pre_save inheritance inherited save | |
Cc: | thesunlover@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello.
I have a base-class and a child-class. The child-class has a pre_save signal and it has a list of related items to it.
when testing for save action django raises DoesNotExist exception. Traceback follows:
Thank you for the time spent on the Django project
File "../children_pre_save_problem/test_b/tests.py", line 9, in test1_inc_num
invo.save()
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 432, in save_base
signals.pre_save.send(sender=origin, instance=self, raw=raw)
File "/usr/lib/pymodules/python2.6/django/dispatch/dispatcher.py", line 166, in send
response = receiver(signal=self, sender=sender, named)
File "/home/iskren/tc/python/children_pre_save_problem/test_b/models.py", line 30, in invoicedoc_pre_save
instance.recalc_total()
File "/home/iskren/tc/python/children_pre_save_problem/test_b/models.py", line 19, in recalc_total
for item in self.item_set.all():
File "/usr/lib/pymodules/python2.6/django/db/models/fields/related.py", line 324, in get
self.related.model._default_manager.class)
File "/usr/lib/pymodules/python2.6/django/db/models/fields/related.py", line 399, in create_manager
getattr(instance, attname)}
File "/usr/lib/pymodules/python2.6/django/db/models/fields/related.py", line 244, in get
raise self.field.rel.to.DoesNotExist
Attachments (1)
Change History (6)
by , 14 years ago
Attachment: | children_pre_save_problem.tar.gz added |
---|
comment:1 by , 14 years ago
After creating an empty instance of the Child Class and trying to save it, django DoesNotExist exception;
when the inheritance is removed test works fine. Also if I remove the pre_save it works fine, but the wanted result is not achieved.
comment:2 by , 14 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
The solution I used was to check if the primary key of the instance is None and if so skip the code that breaks.
comment:3 by , 14 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:4 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
A DoesNotExist exception is raised because you're trying to iterate over the obtain and iterate over a list of objects related to an object that has not yet been saved.
If you need more details, please ask on django-users.
comment:5 by , 12 years ago
Component: | ORM aggregation → Database layer (models, ORM) |
---|
A Django Program representing the problem, with tests