Re: [Django] #33932: Altering AutoFields with renaming a column crashes on PostgreSQL.

23 views
Skip to first unread message

Django

unread,
Aug 17, 2022, 6:11:17 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Benoît Vinot Roseau Technologies):

* Attachment "0001_initial.py" added.


--
Ticket URL: <https://code.djangoproject.com/ticket/33932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 17, 2022, 6:11:40 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Benoît Vinot Roseau Technologies):

* Attachment "0002_rename_id_son_base_ptr.py" added.

Django

unread,
Aug 17, 2022, 6:12:01 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Benoît Vinot Roseau Technologies):

* Attachment "0003_alter_son_base_ptr.py" added.

Django

unread,
Aug 17, 2022, 6:14:30 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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 Benoît Vinot Roseau Technologies):

I have attached the three migrations files of the small example but you
were too fast for me...

It would be my first contribution...

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:3>

Django

unread,
Aug 17, 2022, 6:18:30 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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 Mariusz Felisiak):

Can you confirm [https://code.djangoproject.com/ticket/33932#comment:2 the
diff] works for you?

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:4>

Django

unread,
Aug 17, 2022, 6:23:31 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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 Benoît Vinot Roseau Technologies):

I confirm it works

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:5>

Django

unread,
Aug 17, 2022, 6:38:31 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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 Mariusz Felisiak):

Great!, I created a regression test inspired by your migrations:
{{#!diff
+ def test_autofield_to_o2o(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Note)
+
+ # Rename the field.
+ old_field = Author._meta.get_field("id")
+ new_field = AutoField(primary_key=True)
+ new_field.set_attributes_from_name("note_ptr")
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ # Alter AutoField to OneToOneField.
+ new_field_o2o = OneToOneField(Note, CASCADE)
+ new_field_o2o.set_attributes_from_name("note_ptr")
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, new_field, new_field_o2o,
strict=True)
+ columns = self.column_classes(Author)
+ field_type, _ = columns["note_ptr_id"]
+ self.assertEqual(
+ field_type,
connection.features.introspected_field_types["IntegerField"]
+ )

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:6>

Django

unread,
Aug 17, 2022, 6:46:54 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: nobody
Technologies |
Type: Bug | Status: new
Component: Migrations | Version: 4.1
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 Mariusz Felisiak):

Replying to [comment:3 Benoît Vinot Roseau Technologies]:
> It would be my first contribution... I can start a PR on GitHub

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:7>

Django

unread,
Aug 17, 2022, 7:16:11 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: Benoît
Technologies | Vinot Roseau Technologies
Type: Bug | Status: assigned

Component: Migrations | Version: 4.1
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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Benoît Vinot Roseau Technologies
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:8>

Django

unread,
Aug 17, 2022, 7:23:11 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot Roseau | Owner: Benoît
Technologies | Vinot Roseau Technologies
Type: Bug | Status: assigned
Component: Migrations | Version: 4.1
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 Benoît Vinot Roseau Technologies):

I have created a PR here with your test and your solution.
https://github.com/django/django/pull/15964

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:9>

Django

unread,
Aug 17, 2022, 7:27:02 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
---------------------------------+----------------------------------------
Reporter: Benoît Vinot | Owner: Benoît Vinot

Type: Bug | Status: assigned
Component: Migrations | Version: 4.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Benoît Vinot):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:10>

Django

unread,
Aug 17, 2022, 7:34:06 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------

Reporter: Benoît Vinot | Owner: Benoît
| Vinot
Type: Bug | Status: assigned
Component: Migrations | Version: 4.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:11>

Django

unread,
Aug 17, 2022, 11:43:55 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot | Owner: Benoît
| Vinot
Type: Bug | Status: closed
Component: Migrations | Version: 4.1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c" e3cb8bc]:
{{{
#!CommitTicketReference repository=""
revision="e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c"
Fixed #33932 -- Fixed altering AutoFields to OneToOneField on PostgreSQL.

Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:12>

Django

unread,
Aug 17, 2022, 11:44:26 AM8/17/22
to django-...@googlegroups.com
#33932: Altering AutoFields with renaming a column crashes on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Benoît Vinot | Owner: Benoît
| Vinot
Type: Bug | Status: closed
Component: Migrations | Version: 4.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"85942cf6692f44d11d6d574b2429d201cc1e0aa7" 85942cf6]:
{{{
#!CommitTicketReference repository=""
revision="85942cf6692f44d11d6d574b2429d201cc1e0aa7"
[4.1.x] Fixed #33932 -- Fixed altering AutoFields to OneToOneField on
PostgreSQL.

Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.

Backport of e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:13>

Reply all
Reply to author
Forward
0 new messages