Opened 10 years ago

Closed 10 years ago

Last modified 7 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: no UI/UX: no


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():

File "/usr/local/lib/python2.5/site-packages/django/core/handlers/" in get_response

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

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

  1. form_data.get('custom', )

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

  1. ip=ip

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

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

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


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 10 years ago by Julien Phalip

milestone: 1.0
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 10 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 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

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

comment:4 Changed 10 years ago by James Tauber

typo in the doc, see #8759

comment:5 Changed 9 years ago by x_O

Docs here
are still in old version, this produces a lot of confusions.

comment:6 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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