Skip to content

Commit

Permalink
fix(database): allow filtering by UUID (#26469)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored and michael-s-molina committed Jan 18, 2024
1 parent 21ba6ca commit 9f9c3a8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ class DatabaseRestApi(BaseSupersetModelRestApi):

edit_columns = add_columns

search_columns = [
"allow_file_upload",
"allow_dml",
"allow_run_async",
"created_by",
"changed_by",
"database_name",
"expose_in_sqllab",
"uuid",
]

search_filters = {"allow_file_upload": [DatabaseUploadEnabledFilter]}

list_select_columns = list_columns + ["extra", "sqlalchemy_uri", "password"]
Expand Down
40 changes: 40 additions & 0 deletions tests/unit_tests/databases/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,46 @@
from sqlalchemy.orm.session import Session


def test_filter_by_uuid(
session: Session,
client: Any,
full_api_access: None,
) -> None:
"""
Test that we can filter databases by UUID.
Note: this functionality is not used by the Superset UI, but is needed by 3rd
party tools that use the Superset API. If this tests breaks, please make sure
that the functionality is properly deprecated between major versions with
enough warning so that tools can be adapted.
"""
from superset.databases.api import DatabaseRestApi
from superset.models.core import Database

DatabaseRestApi.datamodel.session = session

# create table for databases
Database.metadata.create_all(session.get_bind()) # pylint: disable=no-member
session.add(
Database(
database_name="my_db",
sqlalchemy_uri="sqlite://",
uuid=UUID("7c1b7880-a59d-47cd-8bf1-f1eb8d2863cb"),
)
)
session.commit()

response = client.get(
"/api/v1/database/?q=(filters:!((col:uuid,opr:eq,value:"
"%277c1b7880-a59d-47cd-8bf1-f1eb8d2863cb%27)))"
)
assert response.status_code == 200

payload = response.json
assert len(payload["result"]) == 1
assert payload["result"][0]["uuid"] == "7c1b7880-a59d-47cd-8bf1-f1eb8d2863cb"


def test_post_with_uuid(
session: Session,
client: Any,
Expand Down

0 comments on commit 9f9c3a8

Please sign in to comment.