#2331 closed defect (invalid)
Related Field has invalid lookup: icontains
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | gmludo@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
just upgraded to the latest head, and found this.
I could have sworn it was working beforehand.
Traceback (most recent call last): File "/home/data/py/django/core/handlers/base.py" in get_response 74. response = callback(request, *callback_args, **callback_kwargs) File "/home/data/py/zilbo/common/utils/views/filter.py" in _wrapper 37. return generic(request, queryset.filter(**filter), *args, **kw) File "/home/data/py/django/views/generic/list_detail.py" in object_list 45. object_list = paginator.get_page(page - 1) File "/home/data/py/django/core/paginator.py" in get_page 36. object_list = list(self.query_set[offset:offset+limit]) File "/home/data/py/django/db/models/query.py" in __iter__ 103. return iter(self._get_data()) File "/home/data/py/django/db/models/query.py" in _get_data 430. self._result_cache = list(self.iterator()) File "/home/data/py/django/db/models/query.py" in iterator 171. select, sql, params = self._get_sql_clause() File "/home/data/py/django/db/models/query.py" in _get_sql_clause 444. joins2, where2, params2 = self._filters.get_sql(opts) File "/home/data/py/django/db/models/query.py" in get_sql 574. joins2, where2, params2 = val.get_sql(opts) File "/home/data/py/django/db/models/query.py" in get_sql 622. return parse_lookup(self.kwargs.items(), opts) File "/home/data/py/django/db/models/query.py" in parse_lookup 734. joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None) File "/home/data/py/django/db/models/query.py" in lookup_inner 906. params.extend(field.get_db_prep_lookup(lookup_type, value)) File "/home/data/py/django/db/models/fields/related.py" in get_db_prep_lookup 105. raise TypeError, "Related Field has invalid lookup: %s" % lookup_type TypeError at /asset/machine/ Related Field has invalid lookup: icontains
Change History (12)
comment:1 by , 18 years ago
Description: | modified (diff) |
---|
comment:2 by , 18 years ago
OK, ignore my last comment, it was lazy. I looked at the code. Suspicion falls on [3246], but it looks like Russell was not expecting non-standard primary keys in there (maybe?). Are you seeing this on a model that has a custom primary key? If not, why on earth are we in that method?
I'm reluctant to go diving in here trying to fix edge cases whilst Adrian is doing his refactoring. The odds of a patch surviving are small. The whole query dissecting and processing phase is possibly open on his lab table with entrails all over the place.
comment:3 by , 18 years ago
Hi.
It was actually an error on my part.. the field it was it is looking at is a generic relation similar to one in
http://svn.zyons.python-hosting.com/trunk/zilbo/common/forum/models.py
class Forum:: summary_tags
but the error looked weird and didn't use to fail in such a way a week or two ago.
comment:5 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Closing as Ian stated it was an error on his part. Ian: If there's still a problem with Django that needs to be fixed, please reopen.
comment:6 by , 15 years ago
This error raised if use search_fields in admin.py. E.x:
class AnotherModel(models.Model): txt = models.CharField(_('Text'), max_length=255) class MyModel(models.Model): prop = models.ForeignKey(AnotherModel)
You must use:
class MyModelAdmin(admin.ModelAdmin): search_fields = ('prop__txt')
Maybe must raise properly exception?
comment:7 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
I'm getting this in 1.3, some 2 years later than the last comment above.
Same situation as above, using Admin. Any search results in the same error as this ticket:
class DeviceAdmin(admin.ModelAdmin): search_fields = ['name', 'hardware_arch', 'afs_sysname', 'afs_client_rev', ' propertyno', 'calc_roles', 'notes']
This doesn't work either, where 'hardware_arch' is the only foreign key referenced in search_fields:
class HardwareArchitecture(models.Model): name = models.CharField('Architecture', primary_key=True, max_length=40) #... class Device(models.Model): #... hardware_arch = models.ForeignKey(HardwareArchitecture, blank=True, null=True, on_delete=models.DO_NOTHING)
class DeviceAdmin(admin.ModelAdmin): search_fields = ['name', 'hardware_arch__name', 'afs_sysname', 'afs_client_r ev', 'propertyno', 'calc_roles', 'notes']
comment:8 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Ignore me. I am an idiot. Fixed. Re-resolving as invalid.
comment:9 by , 13 years ago
Cc: | added |
---|
If like me, you're looking for the solution of this error message, this is the documentation : https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields
Could you provide an example of what you were doing to trigger this error, please. It is impossible to work it out just from the traceback. A model and a query against it that fails reliably would be nice. Thanks.