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(migration): handle permalink edge cases correctly #23980

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion superset/explore/permalink/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self) -> str:
value = {
"chartId": self.chart_id,
"datasourceId": datasource_id,
"datasourceType": datasource_type,
"datasourceType": datasource_type.value,
"datasource": self.datasource,
"state": self.state,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@

class RestrictedUnpickler(pickle.Unpickler):
def find_class(self, module, name):
raise pickle.UnpicklingError(f"Unpickling of {module}.{name} is forbidden")
if not (module == "superset.utils.core" and name == "DatasourceType"):
raise pickle.UnpicklingError(f"Unpickling of {module}.{name} is forbidden")

return super().find_class(module, name)


class KeyValueEntry(Base):
Expand All @@ -58,14 +61,28 @@ class KeyValueEntry(Base):
def upgrade():
bind = op.get_bind()
session: Session = db.Session(bind=bind)
truncated_count = 0
for entry in paginated_update(
session.query(KeyValueEntry).filter(
KeyValueEntry.resource.in_(RESOURCES_TO_MIGRATE)
)
):
value = RestrictedUnpickler(io.BytesIO(entry.value)).load() or {}
try:
value = RestrictedUnpickler(io.BytesIO(entry.value)).load() or {}
except pickle.UnpicklingError as ex:
if str(ex) == "pickle data was truncated":
# make truncated values that were created prior to #20385 an empty
# dict so that downgrading will work properly.
truncated_count += 1
value = {}
else:
raise

entry.value = bytes(json.dumps(value), encoding="utf-8")

if truncated_count:
print(f"Replaced {truncated_count} corrupted values with an empty value")


def downgrade():
bind = op.get_bind()
Expand Down