Opened 18 years ago

Closed 18 years ago

#2149 closed defect (duplicate)

ProgrammingError : PostgreSQL backend : missing a cast to handle inet with the ILIKE operator

Reported by: guillaume.pratte@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django SVN version and PostgreSQL 8.0

How to reproduce :

  1. Define the following model :
class Session(models.Model):
    username = models.CharField(maxlength = 30)
    ip = models.IPAddressField()
    class Meta:
        unique_together = (("username", "ip"),)
  1. Go in the admin interface
  1. Add a new row for Sessions

It will fail :

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  75. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
  54. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py" in add_stage
  253. errors = manipulator.get_validation_errors(new_data)
File "/usr/lib/python2.4/site-packages/django/forms/__init__.py" in get_validation_errors
  58. errors.update(field.get_validation_errors(new_data))
File "/usr/lib/python2.4/site-packages/django/forms/__init__.py" in get_validation_errors
  351. self.run_validator(new_data, validator)
File "/usr/lib/python2.4/site-packages/django/forms/__init__.py" in run_validator
  341. validator(new_data.get(self.field_name, ''), new_data)
File "/usr/lib/python2.4/site-packages/django/db/models/manipulators.py" in manipulator_validator_unique_together
  296. old_obj = self.manager.get(**kwargs)
File "/usr/lib/python2.4/site-packages/django/db/models/manager.py" in get
  66. return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in get
  202. obj_list = list(clone)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in __iter__
  94. return iter(self._get_data())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in _get_data
  412. self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in iterator
  163. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/util.py" in execute
  12. return self.cursor.execute(sql, params)

  ProgrammingError at /admin/traffaccount/session/add/
  ERROR: operator does not exist: inet ~~* "unknown" HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts. SELECT "traffaccount_session"."id","traffaccount_session"."username","traffaccount_session"."ip","traffaccount_session"."begin_tmst","traffaccount_session"."end_tmst","traffaccount_session"."in_octets","traffaccount_session"."out_octets","traffaccount_session"."in_delta","traffaccount_session"."out_delta" FROM "traffaccount_session" WHERE ("traffaccount_session"."username" ILIKE 'user' AND "traffaccount_session"."ip" ILIKE '123.43.34.234')

I tried this manual SQL to debug:

select * from traffaccount_session where ip ilike cast('127.3.2.5' as inet);
ERROR:  operator does not exist: inet ~~* inet
HINT:  No operator matches the given name and argument type(s). You may need to add explicit type casts.

The correct way seems to be:

select * from traffaccount_session where cast(ip as char(15)) ilike '127.3.2.5';

Change History (1)

comment:1 by Adrian Holovaty, 18 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #708.

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