You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When combining a field from this library with ArrayField if any of the values in the array is None (or should be translated to NULL) an invalid query is generated causing an error like the following:
django.db.utils.DataError: invalid input syntax for type ...
In example, if using InetAddressField the generated SQL is something like
SELECT'{192.168.1.1,None}'::inet[]::inet[];
Using django built-in GenericIPAddressField instead produces the right query:
SELECT'{192.168.1.1,NULL}'::inet[]::inet[];
Here is a sample model with tests to ensure this behaviour:
Looking into django code I see that GenericIPAddressField.get_db_prep_value internally calls connection.ops.adapt_ipaddressfield_value which behaves different from netfields:
When combining a field from this library with
ArrayField
if any of the values in the array is None (or should be translated toNULL
) an invalid query is generated causing an error like the following:In example, if using
InetAddressField
the generated SQL is something likeUsing django built-in
GenericIPAddressField
instead produces the right query:Here is a sample model with tests to ensure this behaviour:
I have seen this issue using Django 4.2 and psycopg 3.1.17.
The text was updated successfully, but these errors were encountered: