Desired:
I should get an error from postgres if existing data doesn't fit in the
new length:
ERROR: value too long for type character varying(5)
Observed:
Any existing data longer than the new_max length is truncated and lost.
This behavior was introducted in #25002, which unconditionally added a
cast to the new type. This changes the default behavior of postgres (which
is to never lose data), to implicitly truncate. Django should not lose
data by default.
--
Ticket URL: <https://code.djangoproject.com/ticket/28816>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Database layer (models, ORM) => Migrations
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:1>
* owner: nobody => ChillarAnand
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:2>
* owner: ChillarAnand => Hasan Ramezani
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:3>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:4>
* status: new => assigned
* version: 1.11 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"1378d665a1c85897d951f2ca9618b848fdbba2e7" 1378d665]:
{{{
#!CommitTicketReference repository=""
revision="1378d665a1c85897d951f2ca9618b848fdbba2e7"
Fixed #28816 -- Prevented silencing data loss when decreasing
CharField.max_length on PostgreSQL.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:6>
Comment (by felixxm):
This solution doesn't prevent silencing data loss when decreasing
`CharField.max_length` for a base field of `ArrayField` (see
[https://github.com/django/django/pull/11817#discussion_r328013173
comment]).
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:7>
Comment (by Simon Charette):
Or decreasing the `size` of an `ArrayField`.
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:8>
Comment (by Hasan Ramezani):
Replying to [comment:7 felixxm]:
> This solution doesn't prevent silencing data loss when decreasing
`CharField.max_length` for a base field of `ArrayField` (see
[https://github.com/django/django/pull/11817#discussion_r328013173
comment]).
[https://github.com/django/django/pull/11847 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:9>
* status: closed => new
* resolution: fixed =>
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:10>
Comment (by Hasan Ramezani):
Reopen the ticket because of @felixxm
[https://code.djangoproject.com/ticket/28816#comment:7 comment].
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:11>
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:12>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:13>
* needs_better_patch: 1 => 0
Comment:
The patch was changed based on @felixxm
[https://github.com/django/django/pull/11847#discussion_r334936154 comment
on the PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:14>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"ef4beafa2ce58a81a56ffd48a20a6153126b611a" ef4beafa]:
{{{
#!CommitTicketReference repository=""
revision="ef4beafa2ce58a81a56ffd48a20a6153126b611a"
Refs #28816 -- Prevented silencing data loss when decreasing
CharField.max_length for ArrayField.base_field on PostgreSQL.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:15>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/28816#comment:16>