#34898: Adding non-deterministic collations to unique CharFields crashes on
PostgreSQL.
-------------------------------------+-------------------------------------
               Reporter:  Mariusz    |          Owner:  nobody
  Felisiak                           |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  4.2
  Migrations                         |       Keywords:  PostgreSQL
               Severity:  Normal     |  collation
           Triage Stage:  Accepted   |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Adding non-deterministic collations to unique `CharField`s crashes on
 PostgreSQL. A regression test:

 {{{#!diff
 diff --git a/tests/schema/tests.py b/tests/schema/tests.py
 index 68b6442794..ba8d9e99ec 100644
 --- a/tests/schema/tests.py
 +++ b/tests/schema/tests.py
 @@ -1402,6 +1402,44 @@ class SchemaTests(TransactionTestCase):
          )
          self.assertIn("field",
 self.get_uniques(CiCharModel._meta.db_table))

 +    @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL
 specific")
 +    @skipUnlessDBFeature(
 +        "supports_collation_on_charfield",
 +        "supports_non_deterministic_collations",
 +    )
 +    def test_add_collation_to_unique_charfield(self):
 +        ci_collation = "case_insensitive"
 +
 +        def drop_collation():
 +            with connection.cursor() as cursor:
 +                cursor.execute(f"DROP COLLATION IF EXISTS
 {ci_collation}")
 +
 +        with connection.cursor() as cursor:
 +            cursor.execute(
 +                f"CREATE COLLATION IF NOT EXISTS {ci_collation} (provider
 = icu, "
 +                f"locale = 'und-u-ks-level2', deterministic = false)"
 +            )
 +        self.addCleanup(drop_collation)
 +
 +        # Create the table.
 +        with connection.schema_editor() as editor:
 +            editor.create_model(AuthorWithUniqueName)
 +        # Add db_collation.
 +        old_field = AuthorWithUniqueName._meta.get_field("name")
 +        new_field = CharField(max_length=255, unique=True,
 db_collation=ci_collation)
 +        new_field.model = AuthorWithUniqueName
 +        new_field.set_attributes_from_name("name")
 +        with connection.schema_editor() as editor:
 +            editor.alter_field(
 +                AuthorWithUniqueName, old_field, new_field, strict=True
 +            )
 +
 +        self.assertEqual(
 +
 self.get_column_collation(AuthorWithUniqueName._meta.db_table, "field"),
 +            ci_collation,
 +        )
 +        self.assertIn("field",
 self.get_uniques(AuthorWithUniqueName._meta.db_table))
 +
      @isolate_apps("schema")
      @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL
 specific")
      @skipUnlessDBFeature(

 }}}



 [https://code.djangoproject.com/ticket/33901#comment:18 Reported by Adam].

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34898>
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/0107018b1cdf0b58-7e6342b8-8468-4a94-b993-973385fa25a7-000000%40eu-central-1.amazonses.com.

Reply via email to