Open lukasjuhrich opened 1 year ago
This was based on a misunderstanding of the scope of the g
proxy: It is lifetime-bound to the application context, however usually there is one application context per request.
Using app.extensions
is fine, however for type-safe access one might go the flask_babel
way and provide well-typed access methods like get_backends(app)
/ get_api(app)
.
Rationale
Instead of using
LocalProxy
s ourselves, we should just store the relevant objects ing
and access that. This would make the code easier to read and more in line with flask tutorials.To make this well-typed, we could add a „type shim“ for
g
, which knows about the stored attributes, and import that.Usages
https://github.com/agdsn/sipa/blob/004bb6a7581229ccc5ea3b375330dfc3e4766b66/sipa/backends/extension.py#L340-L341 https://github.com/agdsn/sipa/blob/004bb6a7581229ccc5ea3b375330dfc3e4766b66/sipa/blueprints/register.py#L22 https://github.com/agdsn/sipa/blob/004bb6a7581229ccc5ea3b375330dfc3e4766b66/sipa/model/sample/user.py#L38 https://github.com/agdsn/sipa/blob/004bb6a7581229ccc5ea3b375330dfc3e4766b66/sipa/model/pycroft/user.py#L25 https://github.com/agdsn/sipa/blob/004bb6a7581229ccc5ea3b375330dfc3e4766b66/sipa/model/pycroft/userdb.py#L47