#34840: Django 4.2 casts text fields when testing IS NULL, preventing use of
partial indexes
-------------------------------------+-------------------------------------
Reporter: Alex Vandiver | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Florian, yeah that's the gist of it.
This approach has existed for a while in the ORM to avoid performing a
query for `filter(somefield__in=[])` as SQL doesn't allow `"column" IN ()`
anyway and we've leaned on it recently to prevent some full table scan on
Postgres (#27397) and issues with `NULL` handling when dealing with
`JSONField` (#34754).
I think it makes sense to use this approach in cases where Python input
poses type ambiguity at the database level like it did with the `IN`
operator, after all we were forced to add `::text` cast because Postgres
doesn't know what the type of `%s IS NULL` should be.
In all cases the adjustments to `Q.check` to handle `EmptyResultSet`
should be added as other lookups could generate it, the same can be said
with `FullResultSet`.
I think we should not let the discussion about the silencing of
`DatabaseError` die off though and consider a deprecation path to raise
the awareness of the issue. Maybe a possible alternative solution that
doesn't warrant expression introspection (e.g. special casing `RawSQL`)
could be a `Constraint` kwarg that allows disabling model level validation
entirely? That could be a way to silence the warning during the
deprecation period.
--
Ticket URL: <https://code.djangoproject.com/ticket/34840#comment:19>
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/0107018aafaba0d6-28561952-6ded-47c4-9e27-03f82167850d-000000%40eu-central-1.amazonses.com.