Opened 8 years ago

Closed 7 years ago

#5648 closed (wontfix)

__init__ of Models not overrideable

Reported by: Armin Ronacher Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Apparently django is calling __init__ for models created from database data. This makes it impossible to override the constructor that has a different signature.

It would make more sense if the database API is creating a verbatim instance of the class using object.__new__(Model) and updating the attributes. It would also be possible to add a construct method that is called when a model is assembled from database data.

I can provide a patch if wanted.

Change History (2)

comment:1 Changed 8 years ago by Simon G <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by mtredinnick

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

Django is using the initialisation function on a class to create instances of that class. That's what __init__ is for. You can easily override it, but you have to be able to accept the way a Model class is called, which means accepting things matching the current signature. That's true whenever you subclass something: if you pass it to something that expects the parent, you have to match the parent's initialisation interface.

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