dpgaspar commented on code in PR #23888: URL: https://github.com/apache/superset/pull/23888#discussion_r1182229236
########## superset/migrations/versions/2023-05-01_12-03_9c2a5681ddfd_convert_key_value_entries_to_json.py: ########## @@ -0,0 +1,73 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""convert key-value entries to json + +Revision ID: 9c2a5681ddfd +Revises: 7e67aecbf3f1 +Create Date: 2023-05-01 12:03:17.079862 + +""" + +# revision identifiers, used by Alembic. +revision = "9c2a5681ddfd" +down_revision = "7e67aecbf3f1" + +import json +import pickle + +from alembic import op +from sqlalchemy import Column, Integer, LargeBinary, String +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import Session + +from superset import db +from superset.migrations.shared.utils import paginated_update + +Base = declarative_base() +VALUE_MAX_SIZE = 2**24 - 1 +RESOURCES_TO_MIGRATE = ("app", "dashboard_permalink", "explore_permalink") + + +class KeyValueEntry(Base): + __tablename__ = "key_value" + id = Column(Integer, primary_key=True) + resource = Column(String(32), nullable=False) + value = Column(LargeBinary(length=VALUE_MAX_SIZE), nullable=False) + + +def upgrade(): + bind = op.get_bind() + session: Session = db.Session(bind=bind) + for entry in paginated_update( + session.query(KeyValueEntry).filter( + KeyValueEntry.resource.in_(RESOURCES_TO_MIGRATE) + ) + ): + value = pickle.loads(entry.value) or {} Review Comment: Can we identify the classes that we allow for here? and use Unpickler and find_class ########## superset/key_value/types.py: ########## @@ -42,3 +47,27 @@ class KeyValueResource(str, Enum): class SharedKey(str, Enum): DASHBOARD_PERMALINK_SALT = "dashboard_permalink_salt" EXPLORE_PERMALINK_SALT = "explore_permalink_salt" + + +class KeyValueCodec(ABC): + def encode(self, value: Any) -> bytes: Review Comment: nit: how about: ``` python class KeyValueCodec(ABC): @abstractmethod def encode(self, value: Any) -> bytes: ... @abstractmethod def decode(self, value: bytes) -> Any: ... ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
