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

Cookie transport must return empty json and not null in response.data on login #1037

Merged

Conversation

caniko
Copy link
Contributor

@caniko caniko commented Jul 21, 2022

This causes issues when integrating the openapi schema into openapi-generator. Because the code generator expects the response to be a JSON, as it should be.

@frankie567
Copy link
Member

I understand the issue here. I was wondering: will the OpenAPI generator be happy if we properly define a 204 response with no content? Sounds like the most correct way to define this response to me.

@caniko
Copy link
Contributor Author

caniko commented Jul 22, 2022

I understand the issue here. I was wondering: will the OpenAPI generator be happy if we properly define a 204 response with no content? Sounds like the most correct way to define this response to me.

Right! That is aesthetically more pleasing.

However, it didn't work back in January 31st this year for this guy. He came up wirh some hacky middleware solution.

We would have to test, and see. I do think 204 makes the most sense, but it will be irritating if the openapi-generator is bugged.

I'll do some more digging and testing today. And post my results here.

Just fyi, everything ran fine when it was empty json

@frankie567
Copy link
Member

frankie567 commented Jul 22, 2022

Hmm I guess it's still around: OpenAPITools/openapi-generator#7720 Those 204 responses definitely cause lot of issues 😅

If you have the chance to try, and confirm it's not working, it could be nice. Otherwise, let's go for the empty JSON. The unit test will need to be updated.

Another thing: could you revert the version bumping? This is something I do automatically with a script when I create a release.

…onse with status code 204 when body is empty.

The database backend login response is a cookie header with empty body. This causes issues when integrating the openapi schema into openapi-generator. Because the code generator expects the response to be a JSON when the status code isn't 204.
@caniko caniko force-pushed the CookieTransportEmptyJSONResponseOnLogin branch from 4c1daa8 to bbe39c8 Compare July 22, 2022 10:18
@caniko
Copy link
Contributor Author

caniko commented Jul 22, 2022

I am done testing, and everything ran fine with 204 on my end; however, I only tested for dart-dio with the openapi-generator, there may be issues with other languages. Pedantically speaking, it isn't an issue on our side, but I am not sure if it is OK to neglect for practical reasons. I reverted my empty JSON change for now, I can add it back if you would like.

We should require Fastapi 0.79, coincidentally the latest version 😅, as this is when the 204 issue was fixed on the fastapi side. I made the change to pyproject.toml.

Ready to merge!

@codecov
Copy link

codecov bot commented Jul 22, 2022

Codecov Report

Merging #1037 (b1db927) into master (d0c295e) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            master     #1037    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           20        35    +15     
  Lines          717       957   +240     
==========================================
+ Hits           717       957   +240     
Impacted Files Coverage Δ
fastapi_users/__init__.py 100.00% <100.00%> (ø)
fastapi_users/authentication/__init__.py 100.00% <100.00%> (ø)
fastapi_users/authentication/authenticator.py 100.00% <100.00%> (ø)
fastapi_users/authentication/backend.py 100.00% <100.00%> (ø)
fastapi_users/authentication/strategy/__init__.py 100.00% <100.00%> (ø)
fastapi_users/authentication/strategy/base.py 100.00% <100.00%> (ø)
...stapi_users/authentication/strategy/db/__init__.py 100.00% <100.00%> (ø)
...astapi_users/authentication/strategy/db/adapter.py 100.00% <100.00%> (ø)
fastapi_users/authentication/strategy/db/models.py 100.00% <100.00%> (ø)
...stapi_users/authentication/strategy/db/strategy.py 100.00% <100.00%> (ø)
... and 27 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@frankie567
Copy link
Member

Great! I consider we are doing the right thing here, so let's go with it and we'll see if some OpenAPI generators cause issues to some people.

I took the liberty to slightly change your approach by building a full response manually. This way, we still be compatible with older FastAPI.

Thank you for your raising this point and your help 👍

@frankie567 frankie567 merged commit 77d0077 into fastapi-users:master Jul 22, 2022
@frankie567
Copy link
Member

@all-contributors add @caniko for bug

@allcontributors
Copy link
Contributor

@frankie567

I've put up a pull request to add @caniko! 🎉

@caniko
Copy link
Contributor Author

caniko commented Jul 22, 2022

Thank you for this awesome package!

@frankie567 you reverted the versioning on pyproject.toml from fastapi=0.79.0 to the original. Was this a mistake? I can make a new PR!

@caniko caniko deleted the CookieTransportEmptyJSONResponseOnLogin branch July 22, 2022 14:05
@frankie567
Copy link
Member

Thanks!

No, I did it on purpose: since we build a custom raw Response, we can use older FastAPI version, it won't provoke the 204 response bug.

@caniko
Copy link
Contributor Author

caniko commented Jul 22, 2022

I took the liberty to slightly change your approach by building a full response manually. This way, we still be compatible with older FastAPI.

I see, I misunderstood this statement! Have a good weekend 😁

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.

None yet

2 participants