Re: [Django] #34820: Migrations crashes when changing ForeignObject properties.

11 views
Skip to first unread message

Django

unread,
Sep 9, 2023, 5:49:36 AM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* needs_tests: 1 => 0


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

Django

unread,
Sep 9, 2023, 6:20:25 AM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(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 Mariusz Felisiak):

A regression test:
{{{#!diff
diff --git a/tests/migrations/test_operations.py
b/tests/migrations/test_operations.py
index d4fc3e855a..6366ccd667 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -2306,6 +2306,46 @@ class OperationTests(OperationTestBase):
operation.database_forwards(app_label, editor, new_state,
project_state)
self.assertColumnExists(rider_table, "pony_id")

+ def test_alter_field_foreignobject_noop(self):
+ app_label = "test_alflfo_noop"
+ project_state = self.set_up_test_model(app_label)
+ project_state = self.apply_operations(
+ app_label,
+ project_state,
+ [
+ migrations.CreateModel(
+ "Rider",
+ fields=[
+ ("pony_id", models.IntegerField()),
+ (
+ "pony",
+ models.ForeignObject(
+ f"{app_label}.Pony",
+ models.CASCADE,
+ from_fields=("pony_id",),
+ to_fields=("id",),
+ ),
+ ),
+ ],
+ ),
+ ],
+ )
+ operation = migrations.AlterField(
+ "Rider",
+ "pony",
+ models.ForeignObject(
+ f"{app_label}.Pony",
+ models.CASCADE,
+ from_fields=("pony_id",),
+ to_fields=("id",),
+ null=True,
+ ),
+ )
+ new_state = project_state.clone()
+ operation.state_forwards(app_label, new_state)
+ with self.assertNumQueries(0), connection.schema_editor() as
editor:
+ operation.database_forwards(app_label, editor, project_state,
new_state)
+
@skipUnlessDBFeature("supports_comments")
def test_alter_model_table_comment(self):
app_label = "test_almotaco"

}}}

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

Django

unread,
Sep 9, 2023, 9:30:32 AM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(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 puc_dong):

Replying to [comment:13 Mariusz Felisiak]:

I realized that there will be a default exclude behavior, and there are 6
queries that will be executed in database setup, so I modified the use
case, and the 6 queries were not written directly.
This is my modification:https://github.com/django/django/pull/17240

--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:14>

Django

unread,
Sep 9, 2023, 9:41:14 AM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | 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 Jacob Walls):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:15>

Django

unread,
Sep 9, 2023, 3:08:33 PM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: puc_dong
Type: Bug | Status: assigned

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | 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):

* owner: nobody => puc_dong
* status: new => assigned
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:16>

Django

unread,
Sep 9, 2023, 4:16:30 PM9/9/23
to django-...@googlegroups.com
#34820: Migrations crashes when changing ForeignObject properties.
-------------------------------------+-------------------------------------
Reporter: puc_dong | Owner: puc_dong
Type: Bug | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | 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:"71820c9f91a70076526e2f526236fc4172d92fea" 71820c9f]:
{{{
#!CommitTicketReference repository=""
revision="71820c9f91a70076526e2f526236fc4172d92fea"
Fixed #34820 -- Fixed migrations crash when changing a ForeignObject
field.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:17>

Reply all
Reply to author
Forward
0 new messages