concentricsky / django-tastypie-swagger

An adapter to use swagger-ui with django-tastypie.
Other
132 stars 144 forks source link

KeyError for filters with ALL_WITH_RELATIONS #100

Open soheltarir opened 9 years ago

soheltarir commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 https://github.com/concentricsky/django-tastypie-swagger/pull/108 will solve this problem?