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 error handler type hint, use flask defined route response types #39

Closed

Conversation

Yun-L
Copy link

@Yun-L Yun-L commented Sep 2, 2023

  • replaced FlaskResponseType with the ResponseReturnValue type from flask.typing

@Yun-L Yun-L linked an issue Sep 2, 2023 that may be closed by this pull request
def success(cls, data: JSONType) -> FlaskResponseType:
return data, HTTPStatus.OK
def success(cls, data: JSONType) -> ResponseReturnValue:
return json.dumps(data), HTTPStatus.OK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does change output when using curl. I'm not sure if this will cause issues when we implement the frontend.

Steps to reproduce:

  1. Generate id token. See Write a script to generate a sample id_token #31 for details
  2. Set the ID token to a variable token in shell
  3. Run the backend and run this command
curl -X GET -H "Authorization: Bearer $token" -H 'Content-Type: application/json' localhost:3001/me

Output before MR:

{
    "name": "test",
    "email": "[email protected]",
    "database": null
}

Output after MR:

"{\"name\": \"test\", \"email\": \"[email protected]\", \"database\": null}"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind. I did a test and this isn't a problem for browsers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this change the headers in the response? i'm guessing if the headers don't say its a json curl might default to displaying as a string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't change the headers. My guess is that json.dumps() changes the formatting to include \

After Changes:

Internal server errorgcarvellas@razer-blade-15:~$ curl -v -X GET localhost:3001/health
Note: Unnecessary use of -X or --request, GET is already inferred.
* processing: localhost:3001/health
*   Trying [::1]:3001...
* Connected to localhost (::1) port 3001
> GET /health HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/8.2.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Thu, 14 Sep 2023 18:57:58 GMT
< Connection: keep-alive
< Content-Type: application/json
< Content-Length: 9
< Access-Control-Allow-Origin: *
< 
"\"ok\""

Before Changes:

gcarvellas@razer-blade-15:~$ curl -v -X GET localhost:3001/health
Note: Unnecessary use of -X or --request, GET is already inferred.
* processing: localhost:3001/health
*   Trying [::1]:3001...
* Connected to localhost (::1) port 3001
> GET /health HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/8.2.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Thu, 14 Sep 2023 18:58:40 GMT
< Connection: keep-alive
< Content-Type: application/json
< Content-Length: 5
< Access-Control-Allow-Origin: *
< 
"ok"

@gcarvellas
Copy link
Contributor

closing this since we're not using Flask anymore

@gcarvellas gcarvellas closed this Oct 7, 2023
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.

Mypy fails when exception handler is turned on
2 participants