diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index c347948f7ed70..7b92819fdb77e 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -48,6 +48,7 @@ export type DatabaseObject = { engine?: string; extra?: string; id?: number; + uuid?: null | string; name: string; // synonym to database_name paramProperties?: Record; sqlalchemy_uri?: string; diff --git a/superset/databases/api.py b/superset/databases/api.py index c28519874747f..a8de0b66d2b50 100644 --- a/superset/databases/api.py +++ b/superset/databases/api.py @@ -325,6 +325,7 @@ def post(self) -> FlaskResponse: return self.response_400(message=error.messages) try: new_model = CreateDatabaseCommand(item).run() + item["uuid"] = new_model.uuid # Return censored version for sqlalchemy URI item["sqlalchemy_uri"] = new_model.sqlalchemy_uri item["expose_in_sqllab"] = new_model.expose_in_sqllab diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py index e318e41121435..c4f37fa172029 100644 --- a/superset/databases/schemas.py +++ b/superset/databases/schemas.py @@ -479,6 +479,7 @@ class Meta: # pylint: disable=too-few-public-methods is_managed_externally = fields.Boolean(allow_none=True, default=False) external_url = fields.String(allow_none=True) ssh_tunnel = fields.Nested(DatabaseSSHTunnel, allow_none=True) + uuid = fields.String(required=False) class DatabaseTestConnectionSchema(Schema, DatabaseParametersSchemaMixin): diff --git a/tests/unit_tests/databases/api_test.py b/tests/unit_tests/databases/api_test.py index 68a9add12e9a4..251eb6cdd3240 100644 --- a/tests/unit_tests/databases/api_test.py +++ b/tests/unit_tests/databases/api_test.py @@ -50,6 +50,10 @@ def test_post_with_uuid( ) assert response.status_code == 201 + # check that response includes UUID + payload = response.json + assert payload["result"]["uuid"] == "7c1b7880-a59d-47cd-8bf1-f1eb8d2863cb" + database = session.query(Database).one() assert database.uuid == UUID("7c1b7880-a59d-47cd-8bf1-f1eb8d2863cb")