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

Fix serialization of grants for REST API #6346

Merged
merged 2 commits into from
Apr 1, 2020

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Mar 31, 2020

Description

This PR fixes an issue encountered when trying to retrieve grant information through a REST API.
The REST API is not documented, yet exists.

Refers/Fixes

Steps to reproduce:

active: "error",
code: 500,
nav: "home",
title: "Error 500"
}```
Locally, go to `http://localhost:8000/api/v0.1/grants/`, showing the full stacktrace:
```172.20.0.1 - - [31/Mar/2020 23:24:26] "GET /api/v0.1/grants/ HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/contrib/staticfiles/handlers.py", line 65, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/wsgi.py", line 141, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 75, in get_response
    response = self._middleware_chain(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 36, in inner
    response = response_for_exception(request, exc)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 90, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 125, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/technical_response.py", line 37, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/viewsets.py", line 116, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/mixins.py", line 48, in list
    return Response(serializer.data)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 768, in data
    ret = super(ListSerializer, self).data
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 262, in data
    self._data = self.to_representation(self.instance)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 686, in to_representation
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 686, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 513, in to_representation
    fields = self._readable_fields
  File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 376, in _readable_fields
    field for field in self.fields.values()
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 363, in fields
    for key, value in self.get_fields().items():
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 1050, in get_fields
    source, info, model, depth
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 1195, in build_field
    return self.build_unknown_field(field_name, model_class)
  File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 1307, in build_unknown_field
    (field_name, model_class.__name__)
Testing

@owocki
Copy link
Contributor

owocki commented Apr 1, 2020

this LGTM, @danlipert ?

@danlipert
Copy link
Contributor

@owocki looks good - thanks @atoulme !

@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@be64e9e). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #6346   +/-   ##
=========================================
  Coverage          ?   27.64%           
=========================================
  Files             ?      281           
  Lines             ?    26054           
  Branches          ?     3841           
=========================================
  Hits              ?     7202           
  Misses            ?    18588           
  Partials          ?      264
Impacted Files Coverage Δ
app/grants/serializers.py 100% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be64e9e...57f6fc3. Read the comment docs.

@owocki owocki merged commit 3e9224c into gitcoinco:master Apr 1, 2020
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

Successfully merging this pull request may close these issues.

3 participants