#35336: Adding GeneratedField fails with ProgrammingError when using When on
CharField
-------------------------------------+-------------------------------------
Reporter: Adrian Garcia | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres, | Triage Stage: Accepted
generatedfield, contains |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* component: Migrations => Database layer (models, ORM)
* keywords: postgres, generatedfield, _split_query => postgres,
generatedfield, contains
* owner: nobody => Simon Charette
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* status: new => assigned
Comment:
This can be reproduced on `psycopg2` and `psycopg>=3` and is reminiscent
of the series of issues we had to fix with `Constraint`'s usage of
`__contains` lookup which require proper `%` escaping (#30408, #34553,
#32369)
{{{#!diff
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index f8e314d270..3b2d7bf03c 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -886,6 +886,27 @@ class Meta:
with connection.schema_editor() as editor:
editor.create_model(GeneratedFieldOutputFieldModel)
+ @isolate_apps("schema")
+ @skipUnlessDBFeature("supports_stored_generated_columns")
+ def test_add_generated_field_contains(self):
+ class GeneratedFieldContainsModel(Model):
+ text = TextField()
+
+ class Meta:
+ app_label = "schema"
+
+ field = GeneratedField(
+ expression=Q(text__icontains="FOO"),
+ db_persist=True,
+ output_field=BooleanField(),
+ )
+ field.contribute_to_class(GeneratedFieldContainsModel,
"some_field")
+
+ with connection.schema_editor() as editor:
+ editor.create_model(GeneratedFieldContainsModel)
+ editor.add_field(GeneratedFieldContainsModel, field)
+
+
@isolate_apps("schema")
def test_add_auto_field(self):
class AddAutoFieldModel(Model):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35336#comment:1>
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/0107018e834d2bbe-6e75c9da-3384-48e6-9244-f60b5908204b-000000%40eu-central-1.amazonses.com.