Opened 7 months ago

Last modified 5 weeks ago

#28992 new Bug

Querying GenericIPAddressField with a space crashes with DataError on PostgreSQL

Reported by: Vlada Macek Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
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 Vlada Macek)

When I have a GenericIPAddressField of the model in search_fields of a ModelAdmin and then search for example a space, the admin dies with 500 and

DataError: invalid input syntax for type inet: " "

exception is e-mailed.

Change History (4)

comment:1 Changed 7 months ago by Vlada Macek

Description: modified (diff)

comment:2 Changed 7 months ago by Tim Graham

Component: contrib.adminDatabase layer (models, ORM)
Summary: Admin search over GenericIPAddressField with badly formatted IP address causes a DataErrorQuerying GenericIPAddressField with a space crashes with DataError on PostgreSQL
Triage Stage: UnreviewedAccepted

The problem isn't in the admin. For example, GenericIPAddress.objects.filter(ip=' ') also crashes (using the model in tests/model_fields/test_genericipaddressfield.py).

comment:3 Changed 7 months ago by Vlada Macek

I was't this much specific in the Summary as not only space causes the DataError, but apparently a syntactically wrong IPv4/IPv6 address, any of 'string', '10.10.10.300', 'fffg::'.

I selected admin component as I considered the DataError from ORM as part of correct "user interface" to the developer. What is clearly wrong IMHO is 500 from using the admin.

Thanks.

comment:4 Changed 5 weeks ago by Claude Paroz

A possible solution would be to validate the value in DatabaseOperations.adapt_ipaddressfield_value. Possibly trying first with our own validator, then round-tripping to the database as last resort. Maybe a ValidationError before running the query may be catched easier than the error coming from the database.

Note: See TracTickets for help on using tickets.
Back to Top