ivelum/djangoql

Unsupported lookup 'iexact' for CharField or join on the field not permitted, perhaps you meant iexact or exact?

nicolazilio opened this issue · 2 comments

Hi there,

I've started receiving the following error from djangoql (v0.13.1)

File "/home/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/lib/python3.6/site-packages/djangoql/admin.py" in introspect
  130.         response = self.djangoql_schema(self.model).as_dict()

File "/home/lib/python3.6/site-packages/djangoql/schema.py" in as_dict
  429.                 [(name, field.as_dict()) for name, field in fields.items()]

File "/home/lib/python3.6/site-packages/djangoql/schema.py" in <listcomp>
  429.                 [(name, field.as_dict()) for name, field in fields.items()]

File "/home/lib/python3.6/site-packages/djangoql/schema.py" in as_dict
  44.             'options': list(self.get_options()) if self.suggest_options else [],

File "./collection_management/admin.py" in get_options
  361.             exclude(username__iexact__in=["AnonymousUser","guest","admin"]).\

File "/home/lib/python3.6/site-packages/django/db/models/query.py" in exclude
  899.         return self._filter_or_exclude(True, *args, **kwargs)

File "/home/lib/python3.6/site-packages/django/db/models/query.py" in _filter_or_exclude
  908.             clone.query.add_q(~Q(*args, **kwargs))

File "/home/lib/python3.6/site-packages/django/db/models/sql/query.py" in add_q
  1290.         clause, _ = self._add_q(q_object, self.used_aliases)

File "/home/lib/python3.6/site-packages/django/db/models/sql/query.py" in _add_q
  1318.                     split_subq=split_subq, simple_col=simple_col,

File "/home/lib/python3.6/site-packages/django/db/models/sql/query.py" in build_filter
  1251.         condition = self.build_lookup(lookups, col, value)

File "/home/lib/python3.6/site-packages/django/db/models/sql/query.py" in build_lookup
  1101.             lhs = self.try_transform(lhs, name)

File "/home/lib/python3.6/site-packages/django/db/models/sql/query.py" in try_transform
  1151.                 "permitted%s" % (name, output_field.__name__, suggestion)

Exception Type: FieldError at /collection_management/oligo/introspect/
Exception Value: Unsupported lookup 'iexact' for CharField or join on the field not permitted, perhaps you meant iexact or exact?

It seems to be becoming from this line of code, strangely enough only when the corresponding model is empty, that is, it doesn't have any records in it.

Any ideas?

Thanks in advance!

Hi @nicolazilio, from what I see the error doesn't seem to be related with DjangoQL. You have custom field definition in your code, and I guess the problem is that it is making a query with iexact__in which is not supported by Django itself. Probably you should be using something like this: https://stackoverflow.com/a/14908214

That worked, thanks a lot for the suggestion.