#36815: Avoid unnecessary prepare_value calls when inserting db_defaults
-------------------------------------+-------------------------------------
Reporter: Adam Sołtysik | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Rish):
Thanks. Also, can you please help me understand why this fix would work
here specifically? I thought about fixing this in the `prepare_value`
method, somewhat like this:
`django/db/models/sql/compiler.py:1722`
{{{
def prepare_value(self, field, value):
from django.db.models.expressions import DatabaseDefault
"""
Prepare a value to be used in a query by resolving it if it is an
expression and otherwise calling the field's get_db_prep_save().
"""
if hasattr(value, "resolve_expression"):
if not isinstance(value, DatabaseDefault):
return value
value = value.resolve_expression(
self.query, allow_joins=False, for_save=True
)
}}}
And an absurd number of testcases failed due to this. Maybe this might be
a problem with my approach of generalization or this optimization is
really specific to the case here. Either way, adding that context would he
helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/36815#comment:5>
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 view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019b3d99b985-8b3dda23-d5c2-4bfe-9938-0478c9b10cd6-000000%40eu-central-1.amazonses.com.