#8662 closed (fixed)
Overriding save() raises error when using Model.objects.create()
Reported by: | pjs | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It seems that when over writing .save() (and maybe other default methods) you should be accepting *args, kwargs and passing it along.
I get an exception when using Model.objects.create():
Traceback:
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
- response = callback(request, *callback_args, callback_kwargs)
File "/home/pjs/site/netlandish/../netlandish/ccproc/views.py" in order_process
- form_data.get('custom', )
File "/home/pjs/site/netlandish/../netlandish/billing/helpers.py" in build_sale
- ip=ip
File "/usr/local/lib/python2.5/site-packages/django/db/models/manager.py" in create
- return self.get_query_set().create(kwargs)
File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py" in create
- obj.save(force_insert=True)
Exception Type: TypeError at /order/1027/
Exception Value: save() got an unexpected keyword argument 'force_insert'
My custom .save() didn't have anything catching force_insert..
The docs don't show this is required.
Change History (6)
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Summary: | over writing save() raises error when using Model.objects.create() → Overriding save() raises error when using Model.objects.create() |
comment:2 by , 16 years ago
This is a docs bug. We should mention the need for force_insert
and force_update
if you want your overridden method to be usable by create()
or get_or_create()
. It's in the BackwardsIncompatibleChanges page, but I forgot to update the docs.
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 15 years ago
Docs here http://www.djangoproject.com/documentation/models/save_delete_hooks/
are still in old version, this produces a lot of confusions.
This is probably a side-effect due to [8673].