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

chore: module scope should not require the app context #28378

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented May 8, 2024

This is a major issue that's been plaguing the backend for a long time. Currently you can't simply run a simple from superset import models (or pretty much any other module import) without getting an error about the app context missing, and/or circular imports

This DRAFT PR tries to evaluate what's getting in the way. So far I've identified:

  • app.config being referenced in module scope, this is mostly easy to fix for common configuration, where we can rely on flask.current_app and avoid module scope
  • dynamic/configurable model: this seems to be the core issue, where say we let people configure their EncryptedField's type
  • some reliance on SecurityManager, and SecurityManager.user_model used as a relationship, I think this can be worked around using sqlalchemy's relationship("use-a-string-reference") call
  • ???

TODO:

  • I think we'd have to deprecate SQLALCHEMY_ENCRYPTED_FIELD_TYPE_ADAPTER altogether (?) unless we can find some solution
  • utils should never depend on the app, the app depends on utils

TO-LOOK-INTO

  • Having a different way to parse the config that doesn't depend on the app context (?)

@pull-request-size pull-request-size bot added size/XL and removed size/L labels May 8, 2024
@github-actions github-actions bot added the api Related to the REST API label May 8, 2024
@github-actions github-actions bot added the risk:db-migration PRs that require a DB migration label May 8, 2024
@github-actions github-actions bot added doc Namespace | Anything related to documentation github_actions Pull requests that update GitHub Actions code labels May 9, 2024
@mistercrunch mistercrunch force-pushed the late_config branch 2 times, most recently from a09b851 to e8b23de Compare May 13, 2024 17:15
@github-actions github-actions bot added github_actions Pull requests that update GitHub Actions code and removed github_actions Pull requests that update GitHub Actions code labels May 13, 2024
@mistercrunch mistercrunch force-pushed the late_config branch 3 times, most recently from d3693a5 to ea449c9 Compare May 23, 2024 22:12
superset/views/base.py Fixed Show fixed Hide fixed
This is a major issue that's been plaguing the backend for a long time. Currently you can't simply run a simple `from superset import models` without getting an error about the app context missing.

This DRAFT PR tries to evaluate what's getting in the way. So far I've identified:

- app.config being referenced in module scope, this is mostly easy to fix for common configuration, where we can rely on flask.current_app and avoid module scope
- dynamic/configurable model: this seems to be the core issue, where say we let people configure their EncryptedField's type
- some reliance on SecurityManager, and SecurityManager.user_model used as a relationship, I think this can be worked around using sqlalchemy's `relationship("use-a-string-reference")` call
- ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API doc Namespace | Anything related to documentation github_actions Pull requests that update GitHub Actions code review:draft risk:db-migration PRs that require a DB migration size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants