Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#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: UI/UX:



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/", line 9, in test1_inc_num

File "/usr/lib/pymodules/python2.6/django/db/models/", line 410, in save

self.save_base(force_insert=force_insert, force_update=force_update)

File "/usr/lib/pymodules/python2.6/django/db/models/", line 432, in save_base

signals.pre_save.send(sender=origin, instance=self, raw=raw)

File "/usr/lib/pymodules/python2.6/django/dispatch/", line 166, in send

response = receiver(signal=self, sender=sender, named)

File "/home/iskren/tc/python/children_pre_save_problem/test_b/", line 30, in invoicedoc_pre_save


File "/home/iskren/tc/python/children_pre_save_problem/test_b/", line 19, in recalc_total

for item in self.item_set.all():

File "/usr/lib/pymodules/python2.6/django/db/models/fields/", line 324, in get


File "/usr/lib/pymodules/python2.6/django/db/models/fields/", line 399, in create_manager

getattr(instance, attname)}

File "/usr/lib/pymodules/python2.6/django/db/models/fields/", line 244, in get


Attachments (1)

children_pre_save_problem.tar.gz (4.2 KB) - added by iskren 5 years ago.
A Django Program representing the problem, with tests

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by iskren

A Django Program representing the problem, with tests

comment:1 Changed 5 years ago by iskren

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 Changed 5 years ago by iskren

  • Owner set to iskren
  • Status changed from new to 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 Changed 5 years ago by iskren

  • Owner iskren deleted
  • Status changed from assigned to new

comment:4 Changed 5 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to 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 Changed 3 years ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top