Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError for filters with ALL_WITH_RELATIONS #100

Open
soheltarir opened this issue Apr 11, 2015 · 2 comments
Open

KeyError for filters with ALL_WITH_RELATIONS #100

soheltarir opened this issue Apr 11, 2015 · 2 comments

Comments

@soheltarir
Copy link

Hi,
I am receiving KeyError when I have ALL_WITH_RELATIONS filtering for my Resource. Below is the snapshot of my filters:
filtering = {
'first_name': ALL,
'last_name': ALL,
'gender': ALL,
'availability': ALL,
'date_of_birth': ALL,
'is_verified': ALL,
'status': ALL,
'user': ALL_WITH_RELATIONS,
'assessment_interview': ALL_WITH_RELATIONS,
'created_on': ALL_WITH_RELATIONS,
'updated_on': ALL_WITH_RELATIONS
}

The following Traceback is thrown by tastypie-swagger:
Internal Server Error: /api/v1/doc/schema/employee/
Traceback (most recent call last):
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = wrapped_callback(request, callback_args, *callback_kwargs)
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view
return self.dispatch(request, args, *kwargs)
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch
return handler(request, args, *kwargs)
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/django/views/generic/base.py", line 154, in get
context = self.get_context_data(**kwargs)
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/views.py", line 138, in get_context_data
'apis': mapping.build_apis(),
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 411, in build_apis
apis = [self.build_list_api(), self.build_detail_api()]
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 383, in build_list_api
list_api['operations'].append(self.build_list_operation(method='get'))
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 334, in build_list_operation
'parameters': self.build_parameters_for_list(method=method),
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 147, in build_parameters_for_list
parameters = self.build_parameters_from_filters(method=method)
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 230, in build_parameters_from_filters
parameters.extend(related_mapping.build_parameters_from_filters(prefix="%s%s
" % (prefix, name)))
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 230, in build_parameters_from_filters
parameters.extend(related_mapping.build_parameters_from_filters(prefix="%s%s
" % (prefix, name)))
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 230, in build_parameters_from_filters
parameters.extend(related_mapping.build_parameters_from_filters(prefix="%s%s
" % (prefix, name)))
File "/home/soheltarir/django-workspace/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py", line 203, in build_parameters_from_filters
has_related_resource = hasattr(self.resource.fields[name], 'get_related_resource')
KeyError: 'job_talent'

@johnraz
Copy link
Contributor

johnraz commented Apr 11, 2015

The filtering your are showing above is not the one involved in the error. It may be related to one of the child resource involved in one of the relation though.

The first thing I can think of is that you are referencing 'job_talent' as a key in another resource's filtering dict and that name is not valid.

AyumuKasuga added a commit to AyumuKasuga/django-tastypie-swagger that referenced this issue Nov 12, 2015
@AyumuKasuga
Copy link

Hello, I have same problem. I use filtering like that:

filtering = dict.fromkeys(queryset.model._meta.get_all_field_names(), ALL_WITH_RELATIONS)

And I have related field in my model.

maybe this #108 will solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants