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

fix(metastore-cache): import dao in methods #29451

Merged

Conversation

villebro
Copy link
Member

@villebro villebro commented Jul 2, 2024

SUMMARY

The recent PR #29344 caused a regression causing importing of the Metastore cache outside the app context to fail. This moves the DAO import into the relevant methods to avoid needing the app context during import time and also changes the imports in the test to ensure they work without an app context.

AFTER

python
Python 3.10.6+ (heads/3.10:57f4472, Aug 30 2022, 12:15:19) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from superset.extensions.metastore_cache import SupersetMetastoreCache
>>>

BEFORE

$ python
Python 3.10.6+ (heads/3.10:57f4472, Aug 30 2022, 12:15:19) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from superset.extensions.metastore_cache import SupersetMetastoreCache
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ville/apple/apache-superset/superset/extensions/metastore_cache.py", line 27, in <module>
    from superset.daos.key_value import KeyValueDAO
  File "/Users/ville/apple/apache-superset/superset/daos/key_value.py", line 32, in <module>
    from superset.key_value.models import KeyValueEntry
  File "/Users/ville/apple/apache-superset/superset/key_value/models.py", line 24, in <module>
    from superset.models.helpers import AuditMixinNullable, ImportExportMixin
  File "/Users/ville/apple/apache-superset/superset/models/__init__.py", line 17, in <module>
    from . import core, dynamic_plugins, sql_lab, user_attributes  # noqa: F401
  File "/Users/ville/apple/apache-superset/superset/models/core.py", line 74, in <module>
    from superset.models.helpers import AuditMixinNullable, ImportExportMixin
  File "/Users/ville/apple/apache-superset/superset/models/helpers.py", line 107, in <module>
    config = app.config
  File "/Users/ville/apple/apache-superset/venv/lib/python3.10/site-packages/werkzeug/local.py", line 318, in __get__
    obj = instance._get_current_object()
  File "/Users/ville/apple/apache-superset/venv/lib/python3.10/site-packages/werkzeug/local.py", line 519, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
>>>

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.87%. Comparing base (76d897e) to head (481bc7b).
Report is 403 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #29451       +/-   ##
===========================================
+ Coverage   60.48%   83.87%   +23.38%     
===========================================
  Files        1931      519     -1412     
  Lines       76236    37412    -38824     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    31379    -14735     
+ Misses      28017     6033    -21984     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 49.15% <0.00%> (-0.01%) ⬇️
javascript ?
mysql 77.16% <100.00%> (?)
postgres 77.26% <100.00%> (?)
presto 53.78% <0.00%> (-0.02%) ⬇️
python 83.87% <100.00%> (+20.38%) ⬆️
sqlite 76.74% <100.00%> (?)
unit 59.76% <0.00%> (+2.13%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@villebro villebro merged commit 7f3c8ef into apache:master Jul 2, 2024
45 checks passed
Copy link
Member

@rtexelm rtexelm left a comment

Choose a reason for hiding this comment

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

LGTM, appreciate the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants