Opened 8 years ago
Last modified 5 years ago
#27808 closed Bug
Nested ArrayField with nullable base field generates invalid SQL — at Version 1
Reported by: | Josef Kolář | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When I have model
class NestedNullableIntegerArrayModel(PostgreSQLModel): field = ArrayField(ArrayField(models.IntegerField(null=True)))
and trying to save data
NestedNullableIntegerArrayModel(field=[[None, None], [None, None]]).save()
and Django generates
INSERT INTO "postgres_tests_nestednullableintegerarraymodel" ("field") VALUES (%s) RETURNING "postgres_tests_nestednullableintegerarraymodel"."id"
with expectable params
([[None, None], [None, None]], )
and this query fails in postgres on
ERROR: column "field" is of type integer[] but expression is of type text[] LINE 1: ...estednullableintegerarraymodel" ("field") VALUES (ARRAY['{NU... ^ HINT: You will need to rewrite or cast the expression.
But, if I use one of values is not None, model is saved successfully:
NestedNullableIntegerArrayModel(field=[[None, None], [None, 42]]).save()
Note:
See TracTickets
for help on using tickets.