setup: add api entry points#418
Conversation
|
Have you checked if this affects the API error handlers? i.e. https://github.com/inveniosoftware/invenio-theme/blob/master/invenio_theme/ext.py#L84 vs https://github.com/inveniosoftware/invenio-rest/blob/master/invenio_rest/ext.py#L59 |
Thanks for raising the concern. I just checked, and there shouldn’t be any reason for this change to affect the API error handlers. The two approaches you linked (app.errorhandler(...) and app.register_error_handler(...)) are functionally equivalent in Flask for registering error handlers (see here). In addition, there’s test coverage that verifies the error handlers’ behavior, and all tests are passing without issues. |
|
I agree with @egabancho, we're registering conflicting error handlers for the same response codes, and just because the extension initialization order is random we might getting false positives on tests (i.e. if The approach we usually take in these cases is to have two separate extensions for a UI and REST API version, so the existing |
fenekku
left a comment
There was a problem hiding this comment.
What @slint said :) .
For more context since I delved into this when working on invenio_url_for:
InvenioTheme is only loaded in UI app - this makes sense because REST app doesn't need any UI elements and doesn't want error handlers that would generate HTML pages rather than JSON with error message i.e., like Alex said the double registration would create inconsistencies.
But for generating urls via invenio_url_for, invenio_theme.views:create_blueprint is registered on a temporary app because invenio_base.blueprints is looked up. So if THEME_FRONTPAGE is not loaded in the config, the [] access in create_blueprint will raise a KeyError. That's why it's added in tests so that the API application gets it (e.g., https://github.com/inveniosoftware/invenio-rdm-records/blob/master/tests/conftest.py#L394 ).
But then, how is it available in a live application's API container? (did I ask myself with alarm) It's actually because invenio-app-rdm has this entrypoint: https://github.com/inveniosoftware/invenio-app-rdm/blob/master/setup.cfg#L101 which makes its definition of THEME_FRONTPAGE in config.py be loaded up, thanks to invenio-config .
Bottom line: we shouldn't add invenio-theme to api_apps entrypoint and the setting should be injected in the context you need instead.
|
Now that I understand that this PR is actually about
This is my logical expectation for how config should work. If we have mandatory |
|
To further clarify: even if For the Have we helped the original PR or gone way off tangent 😆 @jrcastro2 ? I think the action item is still to not add this to |
637257e to
c610f74
Compare
|
Thanks a lot for all the clarifications, I see now I missunderstood the original comment 😅 IMHO I agree with the defensive approach of using Let me know if you have other opinons on this, and thanks a lot for the comments! |
|
If it solves the issue, I would recommend we try to switch to @jrcastro2 (or @palkerecsenyi) if you can also add to the PR description some more info or link to what the original issue was for having to add this, it would help. In any case, whatever the decision, we should have a good commit message, since it'll be a small change with a bigger impact to the whole codebase. |
* Switches from direct app.config["THEME_FRONTPAGE"] access to
app.config.get("THEME_FRONTPAGE") to prevent KeyErrors in
environments where the config is not set (e.g. alembic upgrades,
or test contexts)
c610f74 to
ce0153b
Compare
fenekku
left a comment
There was a problem hiding this comment.
Thanks for bearing with that!
No description provided.