#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 <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/0107018a7974f27f-da957d87-5d6c-4cdb-9f44-433d16547abc-000000%40eu-central-1.amazonses.com.

Reply via email to