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(migrations): Fixing cross filter migration #24279

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import copy
import json
import logging

import sqlalchemy as sa
from alembic import op
Expand All @@ -37,6 +38,7 @@
from superset.migrations.shared.utils import paginated_update

Base = declarative_base()
logger = logging.getLogger(__name__)


class Dashboard(Base):
Expand Down Expand Up @@ -72,8 +74,9 @@ def upgrade():
json_metadata["chart_configuration"] = new_chart_configuration
dashboard.json_metadata = json.dumps(json_metadata)

except Exception:
pass
except Exception as e:
logger.exception("Failed to run up migration")
raise e

session.commit()
session.close()
Expand All @@ -91,20 +94,24 @@ def downgrade():
chart_id = config.get("id")
if chart_id is None:
continue
scope = config.get("crossFilters", {}).get("scope", {})
scope = config.get("crossFilters", {}).get("scope", "")
new_chart_configuration[chart_id] = copy.deepcopy(config)
if scope == "global":
if scope.lower() == "global":
new_chart_configuration[chart_id]["crossFilters"]["scope"] = {
"rootPath": ["ROOT_ID"],
"excluded": [chart_id],
}

json_metadata["chart_configuration"] = new_chart_configuration
del json_metadata["global_chart_configuration"]

if "global_chart_configuration" in json_metadata:
del json_metadata["global_chart_configuration"]

Comment on lines +120 to +123
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
if "global_chart_configuration" in json_metadata:
del json_metadata["global_chart_configuration"]
json_metadata.pop('global_chart_configuration')

Copy link
Member

Choose a reason for hiding this comment

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

.pop() fails if the key doesn't exist:

>>> {}.pop(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 1

dashboard.json_metadata = json.dumps(json_metadata)

except Exception:
pass
except Exception as e:
logger.exception("Failed to run down migration")
raise e

session.commit()
session.close()