Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#8662 closed (fixed)

Overriding save() raises error when using Model.objects.create()

Reported by: pjs Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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

  1. response = callback(request, *callback_args, callback_kwargs)

File "/home/pjs/site/netlandish/../netlandish/ccproc/views.py" in order_process

  1. form_data.get('custom', )

File "/home/pjs/site/netlandish/../netlandish/billing/helpers.py" in build_sale

  1. ip=ip

File "/usr/local/lib/python2.5/site-packages/django/db/models/manager.py" in create

  1. return self.get_query_set().create(kwargs)

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py" in create

  1. 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 Changed 8 years ago by Julien Phalip

milestone: 1.0
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: over writing save() raises error when using Model.objects.create()Overriding save() raises error when using Model.objects.create()

This is probably a side-effect due to [8673].

comment:2 Changed 8 years ago by Malcolm Tredinnick

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 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [8689]) Fixed #8662 -- Fixed the documentation of Model.save() to match the real
signature so that people overriding it will use the right signature.

comment:4 Changed 8 years ago by James Tauber

typo in the doc, see #8759

comment:5 Changed 7 years ago by x_O

Docs here http://www.djangoproject.com/documentation/models/save_delete_hooks/
are still in old version, this produces a lot of confusions.

comment:6 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top