#33192: It is not possible to use a custom lookup/transorm in a CheckConstraint
-------------------------------------+-------------------------------------
Reporter: fabien- | Owner: nobody
michel |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) | Keywords: lookup, transform,
Severity: Normal | CheckContraint, migrate
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Using a custom lookup or transform in a **CheckContraint** make migrate
command fail.
{{{
class MonthLastDay(Transform):
lookup_name = "month_last_day"
output_field = DateField()
template = "(DATE_TRUNC('month', %(expressions)s) + (interval '1 month
- 1 day'))::date"
DateField.register_lookup(MonthLastDay)
class MyModel(models.Model):
class Meta:
constraints = [
CheckConstraint(check=Q(date__month_last_day__gte=F("period_start")),
name="date_month_end_after_period_start"),
]
date = models.DateField()
period_start = models.DateField()
}}}
django **makemigrations command** does not indicate any issue with this
and make use of `month_last_day` lookup as if it know about it.
Migration command for this contraint:
{{{
migrations.AddConstraint(
model_name='projectperiodchargetypetaskmonthbudget',
constraint=models.CheckConstraint(
check=models.Q(
('date__month_last_day__gte',
django.db.models.expressions.F('period_start'))
),
name='project_period_charge_type_task_month_budget_month_in_period'),
),
}}}
django **migrate command** fail indicating that `date__month_last_day`
join is not possible
{{{django.core.exceptions.FieldError: Joined field references are not
permitted in this query}}}
I'm not sure what could be done. May be the documentation should warn to
using custom lookup/transform in CheckContraint.
--
Ticket URL: <https://code.djangoproject.com/ticket/33192>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/056.79b5282ff27c321fe0069257dad5ec8c%40djangoproject.com.