-
Notifications
You must be signed in to change notification settings - Fork 41
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
Upgrade to Connexion3 #702
Conversation
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #702 +/- ##
==========================================
- Coverage 99.65% 99.64% -0.02%
==========================================
Files 89 89
Lines 6423 6443 +20
==========================================
+ Hits 6401 6420 +19
- Misses 22 23 +1 ☔ View full report in Codecov by Sentry. |
…o upgrade-to-connexion3
I added added Note that the default port for uvicorn is 8000, whereas for Flask it is 5000. Also the
but this seems to be some version mismatch of starlette. And some All in all, maybe there could be an alternative to Connexion, which could allow still using Flask. |
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 7 New issues |
Starlette-testclient has not pinned (or declared at all?) its anyio dependency, and anyio 4.* do not work with it: Kludex/starlette-testclient#5 Schemathesis v3.2.3 takes this into account and requires anyio <4, but for some reason anyio v4.2.0 gets installed. A workaround is to pin |
When setting CORS in cxapp.add_middleware(
CORSMiddleware,
position=MiddlewarePosition.BEFORE_EXCEPTION,
allow_origins=["*"],
allow_methods=["*"],
) CORS is not working for unit tests:
However, when looking at the response headers in the Firefox network tab, the |
Anyio pinning is not needed anymore, when doing these updates
|
Also curl output shows the CORS header to be sent (when using
|
The CORS testing problem was resolved by removing CORS check from the fuzzying test and (re)creating a dedicated test for it, which adds Origin header to the request: app_client.headers = {"Origin": "http://somedomain.com"} But now there is a (new?) problem: the test_openapi_fuzzy discovered that Edit: The test cases with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this PR and here are some findings:
CLI operation
- The Flask-related commands
routes
andshell
have been dropped. This is good because they're irrelevant for Annif anyway. But the-e, --env-file
and-A, --app
options that seem to be Flask-specific are still there - could we easily get rid of those too? - I timed a few commands (
help
,list-projects
,suggest
) and they don't seem to take longer to run than they used to - some are maybe even a little faster than before. Excellent!
annif run
command
- The console output now looks a bit different than it used to, due to the switch to uvicorn. But I think the new output looks good.
- Annif now listens on port 8000, when it used to listen on port 5000. I think it would be better to keep the old port, because it's documented for example in the Annif tutorial Web UI and REST API exercises. Simply defining a default value of 5000 for
--port
should work, right?
Swagger-UI
- The category view in
/v1/ui
now has a different order - "Learning from feedback" comes last. It's better this way! - Method parameters are also in a different order - not worse than before, maybe even a bit better. The layout for the "Send empty value" checkbox seems a bit broken, though I'm unsure if we can do anything about it. Here is an example that shows old (main) on the left, new (PR branch) on the right:
REST API
- CORS now works differently than before. I'm not sure if this is bad, just something to note (maybe put in the release notes?).
- Before: If there's an
Origin
header in the request, sendAccess-Control-Allow-Origin: <Origin header value>
, otherwise sendAccess-Control-Allow-Origin: *
- After: If there's an
Origin
header in the request, sendAccess-Control-Allow-Origin: *
, otherwise send no such header.
- Before: If there's an
- The URL
/projects/
used to give a 404 response, now it redirects to the correct URL/projects
. Again, not necessarily a problem, just different, and perhaps worth putting into the release notes. - Successful JSON responses are pretty-printed, but error responses in Problem JSON are not. Previously both kinds of JSON responses were pretty-printed for easier readability. I think readable JSON would be good especially for the error messages, since they are likely to be seen by humans at some point.
Other
- SonarCloud has a few complaints - are these real problems?
- CodeClimate also complains of complexity, but it seems like the affected code was already complex, so not really a regression
- Codecov complains about L25 in validation.py not being covered by tests, would it be easy to test this? Or add a notation that excludes it from test coverage?
- See comment about Connexion version specifier
Yes, done.
Yes, done.
Yes, but seems that this cannot be configured, see an old issue: spec-first/connexion#313
I would say no, I silenced them.
Yes, and the code in question is to override a function of Connexion, so it is not meaningful to simplify it. I silenced the complain as "wontfix".
I tried to add test for this line, but it is not detected by CodeCov. I added |
This comment was marked as outdated.
This comment was marked as outdated.
This also reverts the previous commit fc45493. Now uvicorn workers are used always when running with Docker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LVGTM
The test was added in ab33375 The condition is checked before this custom validation
Quality Gate passedIssues Measures |
Upgrades to Connexion 3, closes #689 and #698.
Connexion 3 introduces many changes compared to Connexion 2, see the documentation here.
Most importantly, after the upgrade to Connexion 3, running Annif with Gunicorn requires the use Uvicorn workers; the workers can be set using the
--worker-class/-k
option of Gunicorn:In Dockerfile there is the enviroment variable
GUNICORN_CMD_ARGS="--worker-class uvicorn.workers.UvicornWorker"
, which gives Gunicorn the option by default, so Docker image users do not have to worry about this change.The original PR discussion below beginning from first draft.
This seems to be surprisingly difficult. Connexion 3 documentation states that there are two modes of running/usage of Connexion:
connexion.FlaskApp
connexion.ConnexionMiddleware
to wrap an existing Flask appPreviously Annif has been using the mode 1, and tried to continue with that. But now
And the app needs to be started with
The command
does not know about uvicorn but apparently tries to use plain Flask, and the app won't start.
There are also smaller breaking changes, that needed to be addressed:
Set content-types in response headers in rest methods, because
application/json
andapplication/problem+json
, which seemed to be the cause.)Changing
req.get_json()
->req.json()
in tests, apparently because of "connexion.request is now a Starlette Request instead of a Flask Request".