Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6741 closed (wontfix)

Incomplete documentation for model-inheritance

Reported by: Arnaud Rebts Owned by: nobody
Component: Documentation Version: queryset-refactor
Severity: Keywords: save model-api
Cc: arnaud.rebts@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

If you are using multi-table inheritance, and you want to override the save() method of a base class, you have to specify the optional arguments and pass them to the "real" save() method, as they are used when saving an inherited object.

def save(self, raw=False, cls=None):

do_something()
super(Blog, self).save(raw, cls) # Call the "real" save() method. (don't forget to pass the extra-arguments)
do_something_else()

Attachments (1)

model-api.diff (812 bytes) - added by Arnaud Rebts 6 years ago.
Correction of the documentation.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Arnaud Rebts

Correction of the documentation.

comment:1 Changed 6 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Documentation incorrect for overriding save() to Incomplete documentation for model-inheritance

comment:2 Changed 6 years ago by mtredinnick

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

You're trying to reverse-engineer the documentation to match the incomplete code implementation. The idea is to remove this requirement. Model-inheritance saving is still work in progress.

comment:3 Changed 6 years ago by mtredinnick

  • Patch needs improvement set
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

I think I misunderstood what you were saying here. You're talking about base models, not child models. Actually, this is a non-event in the sense that it's unrelated to model inheritance at all. You should always pass through the standard parameters to the super method if you override the method. On any function you ever override anywhere in Python.

The docs do need an update, though, so reopening.

comment:4 Changed 6 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from reopened to closed

Thinking about this some more, I'm going to go in a different direction. We can remove the need for those extra parameters on the public save() method altogether. Which ducks the issue quite nicely.

comment:5 Changed 6 years ago by mtredinnick

(In [7221]) queryset-refactor: Reorganised Model.save() to differentiate between public and private parameters. Refs #6741.

This means subclasses can override save() without needing to worry about
passing around the internal parameters (an issue for subclassable models, which
would have meant every model, since you don't know when somebody will subclass
your model).

Slightly backwards incompatible, since it moves "raw" back to being part of the
internal API (it's only needed by the serializer and was intended to be
internal use only). If external code really needs this, they can call
Model.save_base() and pass in raw there.

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.