Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#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

  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 by Julien Phalip, 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()

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

comment:2 by Malcolm Tredinnick, 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 Malcolm Tredinnick, 16 years ago

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 by James Tauber, 16 years ago

typo in the doc, see #8759

comment:5 by x_O, 14 years ago

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

comment:6 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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