#35969: Changing output_field for GeneratedField leads to ProgrammingError with
Postgres 16.5+
-----------------------------+------------------------------------
     Reporter:  Ryan Schave  |                    Owner:  (none)
         Type:  Bug          |                   Status:  new
    Component:  Migrations   |                  Version:  5.1
     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):

 It seems to be latter as the above patch works the adjusted tests provided
 by Sarah

 {{{#!diff
 diff --git a/tests/migrations/test_operations.py
 b/tests/migrations/test_operations.py
 index 3ac813b899..7aa3bfbc5d 100644
 --- a/tests/migrations/test_operations.py
 +++ b/tests/migrations/test_operations.py
 @@ -6135,6 +6135,37 @@ def _test_add_generated_field(self, db_persist):
              operation.database_backwards(app_label, editor, new_state,
 project_state)
          self.assertColumnNotExists(f"{app_label}_pony", "modified_pink")

 +    @skipUnlessDBFeature("supports_stored_generated_columns")
 +    def test_generated_field_changes_output_field(self):
 +        app_label = "test_gfcof"
 +        operation = migrations.AddField(
 +            "Pony",
 +            "modified_pink",
 +            models.GeneratedField(
 +                expression=F("pink") + F("pink"),
 +                output_field=models.IntegerField(),
 +                db_persist=True,
 +            ),
 +        )
 +        from_state, to_state = self.make_test_state(app_label, operation)
 +        # Add generated column.
 +        with connection.schema_editor() as editor:
 +            operation.database_forwards(app_label, editor, from_state,
 to_state)
 +        # Update output_field used in the generated field.
 +        operation = migrations.AlterField(
 +            "Pony",
 +            "modified_pink",
 +            models.GeneratedField(
 +                expression=F("pink") + F("pink"),
 +                output_field=models.DecimalField(decimal_places=2,
 max_digits=16),
 +                db_persist=True,
 +            ),
 +        )
 +        from_state = to_state.clone()
 +        to_state = self.apply_operations(app_label, from_state,
 [operation])
 +        with connection.schema_editor() as editor:
 +            operation.database_forwards(app_label, editor, from_state,
 to_state)
 +
      @skipUnlessDBFeature("supports_stored_generated_columns")
      def test_add_generated_field_stored(self):
          self._test_add_generated_field(db_persist=True)
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35969#comment:4>
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/01070193929ae637-9a06e74b-82bf-4827-9917-14aacbbcae06-000000%40eu-central-1.amazonses.com.

Reply via email to