#33647: bulk_update and bulk_create silently truncating values for size limited
fields on postgres
-------------------------------------+-------------------------------------
Reporter: jerch | Owner: Rowan
| Douglas
Type: Bug | Status: assigned
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | 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):
When reviewing the currently proposed patch for #23902 it reminded me that
we also use `Field.db_type` based casting when performing field type
alteration on Postgres since #25002.
We ran into the exact same data truncation problem discussed here in
#28816 by naively using `db_type` casting via `USING` and I only now
realize that we only fixed in 1378d665a1c85897d951f2ca9618b848fdbba2e7 for
a subset of the cases.
We ''fixed'' the problem by not casting when the internal type remains the
same (e.g. `varfield(255) -> varfield(254)`) but the data loss problem
persist when moving from something like `integer` as to `varchar(2)` for
example as `len(str(999)) > 2` obviously.
It stroke me as yet another location where
`Field.db_type(parametrized=False)` would be useful as it would allow us
to
1. Keep not casting via `USING` when the unparametrized type remain the
same (what #28816 started doing)
2. In other case make sure to use `USING %(unparametrized_type)s` to avoid
silent data truncations
Here's [https://dryorm.xterm.info/postgres-alter-type-silent-data-
truncation a DryORM demonstrating the issue]. Not sure if we want a
standalone ticket or if we should fix all the `db_type` based casting
issues (`bulk_update`, schema editor) here.
--
Ticket URL: <https://code.djangoproject.com/ticket/33647#comment:40>
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/0107019bc9945ee8-87f1811c-e705-40f6-9f56-fee367d092d8-000000%40eu-central-1.amazonses.com.