This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch set_examples_db_uuid
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b9aff5ea30c7947790cfbd1737208620042ae8b5
Author: Beto Dealmeida <[email protected]>
AuthorDate: Thu Jul 15 14:41:16 2021 -0700

    chore: set UUID of examples DB
---
 superset/commands/importers/v1/examples.py           | 20 +++++++++++++-------
 superset/constants.py                                |  4 ++++
 .../datasets/examples/users_channels-uzooNNtSRO.yaml |  2 +-
 superset/utils/core.py                               |  3 ++-
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/superset/commands/importers/v1/examples.py 
b/superset/commands/importers/v1/examples.py
index 2b56ee0..9883d16 100644
--- a/superset/commands/importers/v1/examples.py
+++ b/superset/commands/importers/v1/examples.py
@@ -86,16 +86,22 @@ class ImportExamplesCommand(ImportModelsCommand):
                 database_ids[str(database.uuid)] = database.id
 
         # import datasets
-        # TODO (betodealmeida): once we have all examples being imported we can
-        # have a stable UUID for the database stored in the dataset YAML; for
-        # now we need to fetch the current ID.
-        examples_id = (
-            
db.session.query(Database).filter_by(database_name="examples").one().id
-        )
         dataset_info: Dict[str, Dict[str, Any]] = {}
         for file_name, config in configs.items():
             if file_name.startswith("datasets/"):
-                config["database_id"] = examples_id
+                if config["database_uuid"] not in database_ids:
+                    # If database_uuid is not in the list of UUIDs it means 
that
+                    # the examples database was created before its UUID was 
frozen,
+                    # so it has a random UUID. We need to determine its ID so
+                    # we can point the dataset to it.
+                    config["database_id"] = (
+                        db.session.query(Database)
+                        .filter_by(database_name="examples")
+                        .one()
+                        .id
+                    )
+                else:
+                    config["database_id"] = 
database_ids[config["database_uuid"]]
                 dataset = import_dataset(
                     session, config, overwrite=overwrite, force_data=force_data
                 )
diff --git a/superset/constants.py b/superset/constants.py
index a4f0ad1..7defc34 100644
--- a/superset/constants.py
+++ b/superset/constants.py
@@ -21,6 +21,10 @@
 NULL_STRING = "<NULL>"
 
 
+# UUID for the examples database
+EXAMPLES_DB_UUID = "a2dc77af-e654-49bb-b321-40f6b559a1ee"
+
+
 class RouteMethod:  # pylint: disable=too-few-public-methods
     """
     Route methods are a FAB concept around ModelView and RestModelView
diff --git 
a/superset/examples/configs/datasets/examples/users_channels-uzooNNtSRO.yaml 
b/superset/examples/configs/datasets/examples/users_channels-uzooNNtSRO.yaml
index f54d061..152ca32 100644
--- a/superset/examples/configs/datasets/examples/users_channels-uzooNNtSRO.yaml
+++ b/superset/examples/configs/datasets/examples/users_channels-uzooNNtSRO.yaml
@@ -73,4 +73,4 @@ columns:
   description: null
   python_date_format: null
 version: 1.0.0
-database_uuid: 566ca280-3da8-967e-4aa4-4b349218736a
+database_uuid: a2dc77af-e654-49bb-b321-40f6b559a1ee
diff --git a/superset/utils/core.py b/superset/utils/core.py
index 936e191..b4e1a49 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -85,6 +85,7 @@ from typing_extensions import TypedDict
 
 import _thread  # pylint: disable=C0411
 from superset.constants import (
+    EXAMPLES_DB_UUID,
     EXTRA_FORM_DATA_APPEND_KEYS,
     EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS,
     EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS,
@@ -1169,7 +1170,7 @@ def get_or_create_db(
 
     if not database and always_create:
         logger.info("Creating database reference for %s", database_name)
-        database = models.Database(database_name=database_name)
+        database = models.Database(database_name=database_name, 
uuid=EXAMPLES_DB_UUID)
         db.session.add(database)
 
     if database:

Reply via email to