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(dataset): handle missing sqla uri in migration #20073

Merged
merged 1 commit into from
May 16, 2022

Conversation

villebro
Copy link
Member

@villebro villebro commented May 16, 2022

SUMMARY

When running the migration a9422eeaae74_new_dataset_models_take_2.py from #19421 I ran into a problem where some old faulty database metadata caused the migration to fail. This adds a check for the truthiness of drivername similar to what's done a few rows above:

if is_physical and drivername and expression:
to ensure that the the migration completes even if the metadata is corrupted.

BEFORE

Traceback (most recent call last):
  File "/Users/ville/src/superset/venv/bin/superset", line 33, in <module>
    sys.exit(load_entry_point('apache-superset', 'console_scripts', 'superset')())
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 601, in main
    return super().main(*args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 445, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask_migrate/cli.py", line 149, in upgrade
    _upgrade(directory, revision, sql, tag, x_arg)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask_migrate/__init__.py", line 98, in wrapped
    f(*args, **kwargs)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/flask_migrate/__init__.py", line 185, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/command.py", line 294, in upgrade
    script.run_env()
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/script/base.py", line 490, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/ville/src/superset/superset/extensions/../migrations/env.py", line 126, in <module>
    run_migrations_online()
  File "/Users/ville/src/superset/superset/extensions/../migrations/env.py", line 118, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/alembic/runtime/migration.py", line 561, in run_migrations
    step.migration_fn(**kw)
  File "/Users/ville/src/superset/superset/migrations/versions/a9422eeaae74_new_dataset_models_take_2.py", line 885, in upgrade
    postprocess_datasets(session)
  File "/Users/ville/src/superset/superset/migrations/versions/a9422eeaae74_new_dataset_models_take_2.py", line 603, in postprocess_datasets
    expression, get_dialect_name(drivername), show_warning=False
  File "/Users/ville/src/superset/superset/utils/memoized.py", line 50, in __call__
    value = self.func(*args, **kwargs)
  File "/Users/ville/src/superset/superset/connectors/sqla/utils.py", line 185, in get_dialect_name
    return SqlaURL(drivername).get_dialect().name
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 189, in get_dialect
    entrypoint = self._get_entrypoint()
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 172, in _get_entrypoint
    cls = registry.load(name)
  File "/Users/ville/src/superset/venv/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 277, in load
    raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:

AFTER

INFO  [alembic.runtime.migration] Running upgrade ad07e4fdbaba -> a9422eeaae74, new_dataset_models_take_2
>> Copy 35 physical tables to sl_tables...
>> Copy 91 SqlaTable to sl_datasets...
   Copy dataset owners...
   Link physical datasets with tables...
>> Copy 1,033 table columns to sl_columns...
   Link all columns to sl_datasets...
>> Copy 101 metrics to sl_columns...
   Link metric columns to datasets...
>> Run postprocessing on 1,134 columns
   [Column 1 to 1,134] 1,011 may be updated
   Assign table column relations...
>> Run postprocessing on 91 datasets
   Process dataset 1~91...
>> Assign new UUIDs to tables...

Adding uuids for `sl_tables`...
Done. Assigned 34 uuids in 0.012s.

>> Drop intermediate columns...
INFO  [alembic.runtime.migration] Running upgrade a9422eeaae74 -> cbe71abde154, fix report schedule and execution log
Revision ID: 6f139c533bea
Revises: cbe71abde154
Create Date: 2021-05-27 16:10:59.567684

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

@villebro villebro requested a review from a team as a code owner May 16, 2022 06:41
@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #20073 (388c15c) into master (1c3c3ae) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master   #20073   +/-   ##
=======================================
  Coverage   66.37%   66.37%           
=======================================
  Files        1715     1715           
  Lines       64179    64179           
  Branches     6753     6753           
=======================================
  Hits        42602    42602           
  Misses      19859    19859           
  Partials     1718     1718           
Flag Coverage Δ
hive 53.70% <ø> (ø)
mysql 82.04% <ø> (ø)
postgres 82.10% <ø> (ø)
presto 53.56% <ø> (ø)
python 82.53% <ø> (ø)
sqlite 81.84% <ø> (ø)
unit 49.14% <ø> (ø)

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


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c3c3ae...388c15c. Read the comment docs.

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix.

@villebro villebro merged commit 4435e53 into apache:master May 16, 2022
hiboyang pushed a commit to datapunchorg/superset that referenced this pull request May 19, 2022
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/XS 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants