From c14183c766e5b48694c7806655f2e93f3ee1496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Boisseau-Sierra?= Date: Thu, 2 Sep 2021 15:07:23 +0100 Subject: [PATCH] fix(import-dashboards): Match db via name not UUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NB: We're here discussing the `import-dashboards` CLI with the `VERSIONED_EXPORT` feature flag *turned ON* — cf. #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, '', the same db connection (same URI) might not have the same UUID on the export instance, and on the import one. (Cf. #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 #15724. Signed-off-by: Étienne Boisseau-Sierra --- superset/commands/importers/v1/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/superset/commands/importers/v1/__init__.py b/superset/commands/importers/v1/__init__.py index 5440470a1633..93e79da9f978 100644 --- a/superset/commands/importers/v1/__init__.py +++ b/superset/commands/importers/v1/__init__.py @@ -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() } @@ -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