Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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.

Attachments (0)

Change History (6)

comment:1 Changed 6 years ago by julien

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

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

comment:2 Changed 6 years ago by mtredinnick

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 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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 6 years ago by jtauber

typo in the doc, see #8759

comment:5 Changed 5 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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.