flag attempts to change signature of __init__ on Models
|Reported by:||straz||Owned by:||zsiciarz|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As a relative Django newbie, I tried to redefine the init method on my Model classes to take additional parameters.
This failed silently - the objects were created but Model.save() did not persist the objects to the database.
I didn't see anything in the Models documentation or FAQ about this, either.
After some searching I found the answer here, namely, "don't do that":
Feature request: add a warning which is thrown whenever you subclass django.db.models.Model
with a nonstandard init method. The wording could be something like: "Changing the calling signature
of init on subclasses of Model may prevent objects from being saved correctly. Try using a
classmethod factory pattern to create objects instead."
Doc request: add this to the Models documentation
Change History (6)
comment:1 Changed 2 years ago by aaugustin
- Component changed from Database layer (models, ORM) to Documentation
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Type changed from New feature to Cleanup/optimization
Changed 2 years ago by zsiciarz
comment:4 Changed 21 months ago by Tim Graham <timgraham@…>
- Resolution set to fixed
- Status changed from new to closed