Skip to content

Commit

Permalink
fix(import-dashboards): Match db via name not UUID
Browse files Browse the repository at this point in the history
NB: We're here discussing the `import-dashboards` CLI with the
`VERSIONED_EXPORT` feature flag *turned ON* — cf. apache#11349

Currently, `superset import-dashboards` looks up at the required
databases (`export/databases/*.yaml`).
If the db URI (`sqlalchemy_uri` key) contains a masked password, then
the script looks up for already existing databases record.

The match is currently done using db UUID. However, '<insert how UUIDs
are generated>', the same db connection (same URI) might not have the
same UUID on the export instance, and on the import one. (Cf. apache#16395)

Thus, we propose to lookup for the db _name_ instead — this would also
allow for updating the db URI between the export and the import
instance.

Note: this change should not be propagated for the demo db, as its UUID
has been frozen in apache#15724.

Signed-off-by: Étienne Boisseau-Sierra <etienne.boisseau-sierra@unipart.io>
  • Loading branch information
EBoisseauSierra committed Sep 6, 2021
1 parent 84be3ae commit c14183c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions superset/commands/importers/v1/__init__.py
Expand Up @@ -75,9 +75,9 @@ def validate(self) -> None:

# load existing databases so we can apply the password validation
db_passwords = {
str(uuid): password
for uuid, password in db.session.query(
Database.uuid, Database.password
database_name: password
for database_name, password in db.session.query(
Database.database_name, Database.password
).all()
}

Expand Down Expand Up @@ -112,8 +112,11 @@ def validate(self) -> None:
# populate passwords from the request or from existing DBs
if file_name in self.passwords:
config["password"] = self.passwords[file_name]
elif prefix == "databases" and config["uuid"] in db_passwords:
config["password"] = db_passwords[config["uuid"]]
elif (
prefix == "databases"
and config["database_name"] in db_passwords
):
config["password"] = db_passwords[config["database_name"]]

schema.load(config)
self._configs[file_name] = config
Expand Down

0 comments on commit c14183c

Please sign in to comment.