#30621: CheckConstraint: outer range contains inner range casts rhs field to
lhs.inner_type
-------------------------------------+-------------------------------------
Reporter: Tilman | Owner: nobody
Koschnick |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have a CheckConstraint:
{{{
CheckConstraint(check=m.Q(outer__contains=m.F('inner')),
name='outer_contains_inner')
}}}
where both outer and inner are DateTimeRangeFields. During migration, the
inner range gets cast to its underlying type:
{{{
ALTER TABLE "test" ADD CONSTRAINT "outer_contains_inner" CHECK ("outer" @>
("inner")::timestamp with time zone)
}}}
The attached patch avoids the cast if both ranges are of compatible type
(have not checked what happens if one is DateRange and the other is
DateTimeRange, though).
Another workaround would be to switch the relation around:
{{{
CheckConstraint(check=m.Q(inner__contained_by=m.F('outer')),
name='inner_contained_by_outer')
}}}
but I feel since both give equal results, they should both be possible.
--
Ticket URL: <https://code.djangoproject.com/ticket/30621>
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/053.096dd88a443d0163b97ad378df60a396%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.