Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(database): allow filtering by UUID #26469

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"changed_by",
"database_name",
"expose_in_sqllab",
"uuid",
]
search_filters = {"allow_file_upload": [DatabaseUploadEnabledFilter]}
allowed_rel_fields = {"changed_by", "created_by"}
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 @@ -29,6 +29,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
Loading