Skip to content

Commit

Permalink
feat: return UUID on database creation (apache#23143)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Feb 22, 2023
1 parent a40c12d commit fbf10c3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type DatabaseObject = {
engine?: string;
extra?: string;
id?: number;
uuid?: null | string;
name: string; // synonym to database_name
paramProperties?: Record<string, any>;
sqlalchemy_uri?: string;
Expand Down
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset/databases/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/databases/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit fbf10c3

Please sign in to comment.