Repository: fossasia/open-event-server

Issue:
Celery tasks API giving 500 when made a GET requests to 'task_url' returned by export API.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
When a GET is made to 'task_url' got from making POST to export API for an event, for example:
GET to ```https://open-event-api.herokuapp.com/v1/tasks/e248732e-b17f-40de-ba5a-de9324944273```, I am gettting response:
```
{  
   "errors":[  
      {  
         "detail":"Unknown error",
         "source":{  
            "pointer":""
         },
         "status":500,
         "title":"Unknown error"
      }
   ],
   "jsonapi":{  
      "version":"1.0"
   }
}
```
However, sometimes, rarely it happens that I get a response of 'WAITING' or 'FAILURE'.


Discussion:
For reference, heroku log

```
2017-08-13T17:31:57.774392+00:00 app[web.1]: [2017-08-13 17:31:57,773] ERROR in app: Exception on /v1/tasks/e248732e-b17f-40de-ba5a-de9324944273 [GET]
2017-08-13T17:31:57.774437+00:00 app[web.1]: Traceback (most recent call last):
2017-08-13T17:31:57.774439+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
2017-08-13T17:31:57.774439+00:00 app[web.1]:     response = self.full_dispatch_request()
2017-08-13T17:31:57.774440+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-08-13T17:31:57.774441+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2017-08-13T17:31:57.774441+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
2017-08-13T17:31:57.774443+00:00 app[web.1]:     return cors_after_request(app.make_response(f(*args, **kwargs)))
2017-08-13T17:31:57.774443+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-08-13T17:31:57.774444+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2017-08-13T17:31:57.774445+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-08-13T17:31:57.774445+00:00 app[web.1]:     rv = self.dispatch_request()
2017-08-13T17:31:57.774446+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
2017-08-13T17:31:57.774447+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2017-08-13T17:31:57.774447+00:00 app[web.1]:   File "/app/app/api/celery_tasks.py", line 32, in celery_task
2017-08-13T17:31:57.774448+00:00 app[web.1]:     return info['result'], info['result']['code']
2017-08-13T17:31:57.774449+00:00 app[web.1]: TypeError: string indices must be integers, not str
```

Resolving patch:
diff --git a/app/api/celery_tasks.py b/app/api/celery_tasks.py
--- a/app/api/celery_tasks.py
+++ b/app/api/celery_tasks.py
@@ -29,7 +29,7 @@ def celery_task(task_id):
         if type(info) == dict:
             # check if is error
             if '__error' in info:
-                return info['result'], info['result']['code']
+                return info['result']
         # return normal
         return jsonify(state='SUCCESS', result=info)
     elif state == 'FAILURE':


Test patch: