MasMadd commented on issue #38413:
URL: https://github.com/apache/superset/issues/38413#issuecomment-4389124315
I also noticed the reported bug in superset version 6.0.0. I noticed that
the problem was that this function relies on the sqalchemy context, which is
not properly initialized when the command is run. What I did was add default
fallback logic using the flask context. Now the command seems to work perfectly
in any situation.
I modified the **discover_encrypted_fields** method in the
**SecretsMigrator** class in the file **superset/utils/encrypt.py**
```
class SecretsMigrator:
def __init__(self, previous_secret_key: str) -> None:
from superset import db
self._db = db
self._previous_secret_key = previous_secret_key
self._dialect: Dialect = db.engine.url.get_dialect()
def discover_encrypted_fields(self) -> dict[str, dict[str,
EncryptedType]]:
"""
Iterates over SqlAlchemy's metadata, looking for EncryptedType
columns along the way. Builds up a dict of
table_name -> dict of col_name: enc type instance
:return:
"""
meta_info: dict[str, Any] = {}
fab_metadata: MetaData = Model.metadata
sup_metadata: sa.MetaData = getattr(self._db.Model, "metadata",
self._db.metadata)
fab_tables = fab_metadata.tables
sup_tables = sup_metadata.tables
sup_tables_names = list(sup_tables.keys())
tables = sup_tables if len(sup_tables_names) > 0 else fab_tables
if len(list(tables.keys())) == 0:
raise Exception("Something wrong is happening, "
"both the Superset and FAB metadata are composed by an empty set
of tables")
for table_name, table in tables.items():
for col_name, col in table.columns.items():
if isinstance(col.type, EncryptedType):
cols = meta_info.get(table_name, {})
cols[col_name] = col.type
meta_info[table_name] = cols
return meta_info
```
--
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]