Django

Code

Ticket #6741 (closed: wontfix)

Opened 9 months ago

Last modified 9 months ago

Incomplete documentation for model-inheritance

Reported by: Arnaud Rebts Assigned to: nobody
Milestone: Component: Documentation
Version: queryset-refactor Keywords: save model-api
Cc: arnaud.rebts@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

model-api.diff (0.8 kB) - added by Arnaud Rebts on 03/09/08 15:15:45.
Correction of the documentation.

Change History

03/09/08 15:15:45 changed by Arnaud Rebts

  • attachment model-api.diff added.

Correction of the documentation.

03/09/08 15:19:26 changed by anonymous

  • needs_better_patch changed.
  • summary changed from Documentation incorrect for overriding save() to Incomplete documentation for model-inheritance.
  • needs_tests changed.
  • needs_docs changed.

03/09/08 15:48:19 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to invalid.

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.

03/10/08 22:44:49 changed by mtredinnick

  • status changed from closed to reopened.
  • needs_better_patch set to 1.
  • resolution deleted.
  • 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.

03/10/08 23:48:15 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to wontfix.

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.

03/11/08 00:36:10 changed 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/Change #6741 (Incomplete documentation for model-inheritance)




Change Properties
Action