Opened 10 years ago

Closed 10 years ago

Last modified 10 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:


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

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

Attachments (1)

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

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by Arnaud Rebts

Attachment: model-api.diff added

Correction of the documentation.

comment:1 Changed 10 years ago by anonymous

Summary: Documentation incorrect for overriding save()Incomplete documentation for model-inheritance

comment:2 Changed 10 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

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

Patch needs improvement: set
Resolution: invalid
Status: closedreopened
Triage Stage: UnreviewedAccepted

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

Resolution: wontfix
Status: reopenedclosed

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

(In [7221]) queryset-refactor: Reorganised 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.

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