{{{
#!python
def old_default_code():
return 'old'
def new_default_code():
# running something that is stateful, for example, increase a database
counter
class Student(models.Model):
code = models.CharField(default=new_default_code)
}}}
We change the default callable object, and run {{{manage.py migrate}}},
ideally {{{new_default_code}}} shouldn't be
called, however, we are getting the model field default value no matter
whether we need it or not:
https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L679
I'd love to send a pull request for this if necessary.
--
Ticket URL: <https://code.djangoproject.com/ticket/31392>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Cleanup/optimization
* component: Migrations => Database layer (models, ORM)
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Agreed, we can add this small optimization, i.e. avoid calling
`SchemaEditor.effective_default()` if we don't change a field to a non-
nullable.
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:1>
* owner: nobody => Shipeng Feng
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/12612 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:4>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"8fe2447a01232d9598bf4692d1face12fa074288" 8fe2447a]:
{{{
#!CommitTicketReference repository=""
revision="8fe2447a01232d9598bf4692d1face12fa074288"
Fixed #31392 -- Avoided unnecessary SchemaEditor.effective_default() calls
when altering a field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31392#comment:6>