#29505: Impossible to set a Field's default value to a callable that takes an
argument
---------------------------------+--------------------------------------
Reporter: Eugene Pakhomov | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 2.0
Severity: Normal | Resolution: wontfix
Keywords: default | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Eugene Pakhomov):
As I said in the issue description - the types under question are not
under my control, so I cannot change `__call__()`. And my concern doesn't
have to do anything with my particular situation - I have already solved
it by setting a custom `DatabaseSchemaEditor`. My concern is that this
issue is still there, and other people will have to spend some time
debugging it.
> field.get_default() may return a callable
You're incorrect. Django itself doesn't do that. And `Model#__init__()`
implementation calls `get_default()` without checking whether it's result
is callable or not because the default implementation of `get_default()`
always does this check. If `get_default()` could return a callable,
`Model#__init__()` would not work correctly - it would set the
corresponding field in all instances to the callable, without calling it
to get the default value.
--
Ticket URL: <https://code.djangoproject.com/ticket/29505#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.dfeea4b32940b058215e6eac89177954%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.