Re: [Django] #35194: Postgres 16.2 with _iexact leads to psycopg2.errors.IndeterminateCollation

2024-02-13 Thread Django
#35194: Postgres 16.2 with _iexact leads to 
psycopg2.errors.IndeterminateCollation
--+--
 Reporter:  Aldalen   |Owner:  (none)
 Type:  Bug   |   Status:  new
Component:  contrib.postgres  |  Version:  5.0
 Severity:  Normal|   Resolution:
 Keywords:| Triage Stage:  Unreviewed
Has patch:  0 |  Needs documentation:  0
  Needs tests:  0 |  Patch needs improvement:  0
Easy pickings:  0 |UI/UX:  0
--+--
Description changed by Aldalen:

Old description:

> There is something up with how "_iexact" GeneratedField expressions are
> handling _iexact expressions.  This leads to a
> "psycopg2.errors.IndeterminateCollation: could not determine which
> collation to use for upper() function" error.   This was caught in our
> CI/CD env when I revved it to 16.2.  Existing / old migrations failed.
> This is a reduced examples from our code, with exception paths redacted
> where necessary.
>
> Model Definition:
>
> {{{
> class TestModel(models.Model):
>  test = models.CharField(max_length=254, blank=True)
>  test_gen =
> models.GeneratedField(expression=models.Q(test__iexact='yes'),
> output_field=models.BooleanField(), db_persist=True)
> }}}
>

> Migration content:
>
> {{{
> migrations.AddField(
> model_name='testmodel',
> name='test_gen',
> field=models.GeneratedField(db_persist=True,
> expression=models.Q(("test__iexact",'yes')),
> output_field=models.BooleanField()),
> )
> }}}
>
> Error:
>
> {{{
>   Applying module.migration_name...Traceback (most recent call last):
>   File "/opt/venv/lib/python3.11/site-
> packages/django/db/backends/utils.py", line 103, in _execute
> return self.cursor.execute(sql)
>
> psycopg2.errors.IndeterminateCollation: could not determine which
> collation to use for upper() function
> HINT:  Use the COLLATE clause to set the collation explicitly.
> The above exception was the direct cause of the following exception:
> Traceback (most recent call last):
>   File "/builds/[redacted]/manage.py", line 15, in 
> execute_from_command_line(sys.argv)
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/__init__.py", line 442, in
> execute_from_command_line
> utility.execute()
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/__init__.py", line 436, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/base.py", line 413, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/base.py", line 459, in execute
> output = self.handle(*args, **options)
>  ^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/base.py", line 107, in wrapper
> res = handle_func(*args, **kwargs)
>   
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/core/management/commands/migrate.py", line 356, in handle
> post_migrate_state = executor.migrate(
>  ^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/migrations/executor.py", line 135, in migrate
> state = self._migrate_all_forwards(
> ^^^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/migrations/executor.py", line 167, in
> _migrate_all_forwards
> state = self.apply_migration(
> ^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/migrations/executor.py", line 252, in apply_migration
> state = migration.apply(state, schema_editor)
> ^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/migrations/migration.py", line 132, in apply
> operation.database_forwards(
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/migrations/operations/fields.py", line 108, in
> database_forwards
> schema_editor.add_field(
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/backends/base/schema.py", line 750, in add_field
> self.execute(sql, params)
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/backends/postgresql/schema.py", line 48, in execute
> return super().execute(sql, None)
>^^
>   File "/opt/[redacted]/lib/python3.11/site-
> packages/django/db/backends/base/schema.py", line 201, in execute
> cursor.execute(sql, params)
>   F

Re: [Django] #35194: Postgres 16.2 with _iexact leads to psycopg2.errors.IndeterminateCollation

2024-02-13 Thread Django
#35194: Postgres 16.2 with _iexact leads to 
psycopg2.errors.IndeterminateCollation
--+--
 Reporter:  Aldalen   |Owner:  (none)
 Type:  Bug   |   Status:  new
Component:  contrib.postgres  |  Version:  5.0
 Severity:  Normal|   Resolution:
 Keywords:| Triage Stage:  Unreviewed
Has patch:  0 |  Needs documentation:  0
  Needs tests:  0 |  Patch needs improvement:  0
Easy pickings:  0 |UI/UX:  0
--+--
Comment (by Aldalen):

 This was tested with django 5.0.2 and latest psycopg2 2.9.9.
-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018da6877e02-34736907-5019-4cb7-920c-66fbac5cc2a8-00%40eu-central-1.amazonses.com.


[Django] #35194: Postgres 16.2 with _iexact leads to psycopg2.errors.IndeterminateCollation

2024-02-13 Thread Django
#35194: Postgres 16.2 with _iexact leads to 
psycopg2.errors.IndeterminateCollation
+
   Reporter:  Michael A |  Owner:  (none)
   Type:  Bug   | Status:  new
  Component:  contrib.postgres  |Version:  5.0
   Severity:  Normal|   Keywords:
   Triage Stage:  Unreviewed|  Has patch:  0
Needs documentation:  0 |Needs tests:  0
Patch needs improvement:  0 |  Easy pickings:  0
  UI/UX:  0 |
+
 There is something up with how "_iexact" GeneratedField expressions are
 handling _iexact expressions.  This leads to a
 "psycopg2.errors.IndeterminateCollation: could not determine which
 collation to use for upper() function" error.   This was caught in our
 CI/CD env when I revved it to 16.2.  Existing / old migrations failed.
 This is a reduced examples from our code, with exception paths redacted
 where necessary.

 Model Definition:

 {{{
 class TestModel(models.Model):
  test = models.CharField(max_length=254, blank=True)
  test_gen =
 models.GeneratedField(expression=models.Q(test__iexact='yes'),
 output_field=models.BooleanField(), db_persist=True)
 }}}


 Migration content:

 {{{
 migrations.AddField(
 model_name='testmodel',
 name='test_gen',
 field=models.GeneratedField(db_persist=True,
 expression=models.Q(("test__iexact",'yes')),
 output_field=models.BooleanField()),
 )
 }}}

 Error:

 {{{
   Applying module.migration_name...Traceback (most recent call last):
   File "/opt/venv/lib/python3.11/site-
 packages/django/db/backends/utils.py", line 103, in _execute
 return self.cursor.execute(sql)

 psycopg2.errors.IndeterminateCollation: could not determine which
 collation to use for upper() function
 HINT:  Use the COLLATE clause to set the collation explicitly.
 The above exception was the direct cause of the following exception:
 Traceback (most recent call last):
   File "/builds/[redacted]/manage.py", line 15, in 
 execute_from_command_line(sys.argv)
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/__init__.py", line 442, in
 execute_from_command_line
 utility.execute()
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/__init__.py", line 436, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/base.py", line 413, in run_from_argv
 self.execute(*args, **cmd_options)
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/base.py", line 459, in execute
 output = self.handle(*args, **options)
  ^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/base.py", line 107, in wrapper
 res = handle_func(*args, **kwargs)
   
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/core/management/commands/migrate.py", line 356, in handle
 post_migrate_state = executor.migrate(
  ^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/migrations/executor.py", line 135, in migrate
 state = self._migrate_all_forwards(
 ^^^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/migrations/executor.py", line 167, in
 _migrate_all_forwards
 state = self.apply_migration(
 ^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/migrations/executor.py", line 252, in apply_migration
 state = migration.apply(state, schema_editor)
 ^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/migrations/migration.py", line 132, in apply
 operation.database_forwards(
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/migrations/operations/fields.py", line 108, in
 database_forwards
 schema_editor.add_field(
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/backends/base/schema.py", line 750, in add_field
 self.execute(sql, params)
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/backends/postgresql/schema.py", line 48, in execute
 return super().execute(sql, None)
^^
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/backends/base/schema.py", line 201, in execute
 cursor.execute(sql, params)
   File "/opt/[redacted]/lib/python3.11/site-
 packages/django/db/backends/utils.py", line 122, in execute
 return super().execute(sql, params)