codeforkansascity / clear_my_record_backend

Backend API Code for Clear My Record, an application to assist people the process of expunging their criminal convictions.
MIT License
5 stars 3 forks source link

Can not POST to convictions #57

Closed zmon closed 5 years ago

zmon commented 5 years ago

POST http://127.0.0.1:5000/clients/2/convictions

{"case_number":"case number","arrest_date":"2001-06-09","agency":"mo circut county court","court_name":"","court_city_county":"Jackson county","judge":"bob j.","record_name":"my full name","release_status":"relased","release_date":"2010-06-06","name":"car theft"}

or with client_id in the data

{"case_number":"case number","client_id": "2", "arrest_date":"2001-06-09","agency":"mo circut county court","court_name":"","court_city_county":"Jackson county","judge":"bob j.","record_name":"my full name","release_status":"relased","release_date":"2010-06-06","name":"car theft"}

gives : 500 INTERNAL SERVER ERROR and no message

From Postman

File "/Users/paulb/tmp/clear_my_record_backend/server/core/routes.py", line 213, in add_client_conviction

    conviction = models.Conviction()
    client.convictions.append(conviction)

    if request.json:
        if "release_date" in request.json:
            request.json["release_date"] = datetime.strptime(request.json["dob"], '%Y-%m-%d').date()
        try:
            conviction.update(request.json)
            dbs.session.add(conviction)
            dbs.session.commit()
            dbs.session.flush()
KeyError: 'dob'
This is the Copy/Paste friendly version of the traceback. You can also paste this traceback into a gist:  create paste

Traceback (most recent call last):
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router
    return original_handler(e)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router
    return original_handler(e)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/paulb/.pyenv/versions/3.6.5/envs/cmr/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/paulb/tmp/clear_my_record_backend/server/core/routes.py", line 213, in add_client_conviction
    request.json["release_date"] = datetime.strptime(request.json["dob"], '%Y-%m-%d').date()
KeyError: 'dob'
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error. If you enable JavaScript you can also use additional features such as code execution (if the evalex feature is enabled), automatic pasting of the exceptions and much more.
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.
ejmg commented 5 years ago

Looks like there was a typo in the code:

            request.json["release_date"] = datetime.strptime(request.json["dob"], '%Y-%m-%d').date()

dob :arrow_right: release_date.

ejmg commented 5 years ago

handled by #59