Skip to content

Commit

Permalink
fix: schemas for upload API (apache#29604)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Jul 16, 2024
1 parent ec508a7 commit b66c0f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ def get_foreign_keys(self, table: Table) -> list[dict[str, Any]]:

def get_schema_access_for_file_upload( # pylint: disable=invalid-name
self,
) -> list[str]:
) -> set[str]:
allowed_databases = self.get_extra().get("schemas_allowed_for_file_upload", [])

if isinstance(allowed_databases, str):
Expand All @@ -993,7 +993,7 @@ def get_schema_access_for_file_upload( # pylint: disable=invalid-name
self, g.user
)
allowed_databases += extra_allowed_databases
return sorted(set(allowed_databases))
return set(allowed_databases)

@property
def sqlalchemy_uri_decrypted(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ def test_update_dashboard_add_tags_can_write_on_tag(self):

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
self.assertEqual(tag_list, new_tags)
self.assertEqual(sorted(tag_list), sorted(new_tags))

@pytest.mark.usefixtures("create_dashboard_with_tag")
def test_update_dashboard_remove_tags_can_write_on_tag(self):
Expand Down
20 changes: 20 additions & 0 deletions tests/unit_tests/models/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,23 @@ def test_raw_connection_oauth(mocker: MockerFixture) -> None:
with database.get_raw_connection() as conn:
conn.cursor()
assert str(excinfo.value) == "You don't have permission to access the data."


def test_get_schema_access_for_file_upload() -> None:
"""
Test the `get_schema_access_for_file_upload` method.
"""
database = Database(
database_name="first-database",
sqlalchemy_uri="gsheets://",
extra=json.dumps(
{
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_file_upload": '["public"]',
}
),
)

assert database.get_schema_access_for_file_upload() == {"public"}

0 comments on commit b66c0f8

Please sign in to comment.