#29505: Impossible to set a Field's default value to a callable
---------------------------------+--------------------------------------
Reporter: Eugene Pakhomov | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 2.0
Severity: Normal | Resolution:
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):
Suppose I have some custom type like this one
{{{
#!python
class MyStr(str):
def __call__(self, other):
return self + other
}}}
and a corresponding custom field type that inherits from Django's
`TextField` and implements all necessary methods so that `MyStr` is used
everywhere instead of the regular `str`.
Currently, it's not possible without manually creating a `DatabaseWrapper`
with a custom `DatabaseSchemaEditor` because even if you handle the fact
that instances of `MyStr` are callable in the custom field type, they will
still be called in
`django.db.backends.base.schema.BaseDatabaseSchemaEditor#effective_default`.
Attached a patch that fixes this issue. Tests appear to be fine.
--
Ticket URL: <https://code.djangoproject.com/ticket/29505#comment:2>
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.d0c870e5a8cd5b1a9a9b021ef687dfe9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.