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

Added convenience variables for middleware and exception handlers #537

Merged
merged 2 commits into from Oct 5, 2020

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Oct 2, 2020

Closes #536.

@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #537 into master will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #537      +/-   ##
==========================================
- Coverage   91.51%   91.47%   -0.04%     
==========================================
  Files          62       62              
  Lines        3123     3110      -13     
==========================================
- Hits         2858     2845      -13     
  Misses        265      265              
Flag Coverage Δ
#project 91.47% <100.00%> (-0.04%) ⬇️
#validator 63.53% <100.00%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/server/exception_handlers.py 83.33% <100.00%> (+0.52%) ⬆️
optimade/server/main.py 94.23% <100.00%> (-0.86%) ⬇️
optimade/server/main_index.py 94.44% <100.00%> (-0.72%) ⬇️
optimade/server/middleware.py 95.00% <100.00%> (+0.06%) ⬆️

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 3917e44...7310237. Read the comment docs.

@ml-evs ml-evs requested a review from CasperWA October 2, 2020 14:23
CasperWA
CasperWA previously approved these changes Oct 3, 2020
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Seems good.

As you point out yourself, we might want to do this for the the exceptions handlers as well, however, this does not seem as straight forward since you need to match the handlers up with Exceptions. But if you have a good idea in mind, I don't mind merging this PR with two distinct commits for each of these (middleware + exception handlers).

Also, do you think REQUIRED_MIDDLEWARE is the best name? Specifically thinking about the REQUIRED part. Maybe just OPTIMADE_MIDDLEWARE?

I have accepted this PR though, since I have no strong opposing opinion on the above points, and am fine with it as is. However, a comment on each point would be good before merging.

@ml-evs ml-evs force-pushed the ml-evs/middlware_convenience branch 2 times, most recently from f020cbe to f9dbb4a Compare October 3, 2020 17:00
@ml-evs
Copy link
Member Author

ml-evs commented Oct 3, 2020

As you point out yourself, we might want to do this for the the exceptions handlers as well, however, this does not seem as straight forward since you need to match the handlers up with Exceptions. But if you have a good idea in mind, I don't mind merging this PR with two distinct commits for each of these (middleware + exception handlers).

Done, didn't seem so bad. Side effect is that the index server will also handle NotImplementedError.

Also, do you think REQUIRED_MIDDLEWARE is the best name? Specifically thinking about the REQUIRED part. Maybe just OPTIMADE_MIDDLEWARE?

I agree that's clearer, so updated it.

I have accepted this PR though, since I have no strong opposing opinion on the above points, and am fine with it as is. However, a comment on each point would be good before merging.

I also added docstrings and typehints to the new constants, which mkdocstrings handles quite nicely (note the docs for the exception_handlers module are currently non-existent, though I'm not over-worried about this...)

@ml-evs ml-evs requested a review from CasperWA October 3, 2020 17:02
@ml-evs ml-evs changed the title Added convenience variable 'REQUIRED_MIDDLEWARE' for server code to load Added convenience variables for middleware and exception handlers Oct 3, 2020
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Nice with the doc strings!

The CORS middleware should be added before our custom middleware due to AddWarnings needing to be last.
It's a bit worrying the tests are not catching this, maybe it was too difficult setting one up properly? But this is what I remember from creating the middleware, and what I also put into its doc string.

optimade/server/main.py Outdated Show resolved Hide resolved
optimade/server/main_index.py Outdated Show resolved Hide resolved
optimade/server/middleware.py Show resolved Hide resolved
optimade/server/exception_handlers.py Show resolved Hide resolved
@ml-evs ml-evs requested a review from CasperWA October 4, 2020 11:10
@ml-evs
Copy link
Member Author

ml-evs commented Oct 4, 2020

But this is what I remember from creating the middleware, and what I also put into its doc string.

Where does it say this in the docs? Struggling to find it. Might be worth adding a note in the docstring of OPTIMADE_MIDDLEWARE too.

@CasperWA
Copy link
Member

CasperWA commented Oct 4, 2020

But this is what I remember from creating the middleware, and what I also put into its doc string.

Where does it say this in the docs? Struggling to find it. Might be worth adding a note in the docstring of OPTIMADE_MIDDLEWARE too.

Yeah, just read it through. What I remembered was this, but that obviously has nothing to do with when to add it to the application.
I should add this. Maybe see if I have written something about it in a commit or PR where this was added.

@ml-evs
Copy link
Member Author

ml-evs commented Oct 4, 2020

I should add this. Maybe see if I have written something about it in a commit or PR where this was added.

Cool, feel free to add it to this PR where/when you please (there's no rush to get this in)

@ml-evs ml-evs force-pushed the ml-evs/middlware_convenience branch from 77fd124 to a23083c Compare October 4, 2020 11:51
@CasperWA
Copy link
Member

CasperWA commented Oct 4, 2020

I should add this. Maybe see if I have written something about it in a commit or PR where this was added.

Cool, feel free to add it to this PR where/when you please (there's no rush to get this in)

Done.
I have added some text to the AddWarnings middleware doc string. Feel free to distribute it around if you feel it's necessary, but maybe we should just link to the middleware and exception handlers instead in the convenience variables?

CasperWA
CasperWA previously approved these changes Oct 4, 2020
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Fine for me now.
As stated above, if you wish to distribute the text I added in other places, feel free, I will re-review later then :)

@ml-evs ml-evs force-pushed the ml-evs/middlware_convenience branch 2 times, most recently from d8ce7cb to 1a617d3 Compare October 5, 2020 10:36
CasperWA
CasperWA previously approved these changes Oct 5, 2020
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Looks great now. I've again approved, since my suggested change is not crucial, I just thought it might make the note look more accessible by having a "one line summary".

optimade/server/middleware.py Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Oct 5, 2020

I'll just quickly rebase this into 2 commits; one for middleware by both of us and one for exception handlers by me

@ml-evs ml-evs force-pushed the ml-evs/middlware_convenience branch from 3ac9446 to a19d996 Compare October 5, 2020 12:03
@ml-evs
Copy link
Member Author

ml-evs commented Oct 5, 2020

I'll just quickly rebase this into 2 commits; one for middleware by both of us and one for exception handlers by me

Done, so much for a short and sweet PR!

- Updated docstrings to clarify importance of middleware ordering, in
particular that AddWarnings must come first/last.

Co-authored-by: Casper Welzel Andersen <casper.andersen@epfl.ch>
@ml-evs ml-evs force-pushed the ml-evs/middlware_convenience branch from a19d996 to 7310237 Compare October 5, 2020 12:11
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Cheers @ml-evs !

@ml-evs ml-evs merged commit 004686c into master Oct 5, 2020
@CasperWA CasperWA deleted the ml-evs/middlware_convenience branch October 5, 2020 13:58
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.

Add convenience method for adding all required middleware
2 participants