Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(datasets): give possibility to add dataset with slashes in name #24796

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cceeb9a
fix(datasets): give possibility to add dataset with slashes in name
Always-prog Jul 25, 2023
d249f7d
tests(database): get table details if table has slash in name
Always-prog Jul 26, 2023
6877406
fix(chore): added type for table_name in the endpoints
Always-prog Jul 26, 2023
0f73a2f
oops
Always-prog Jul 26, 2023
fe0af7f
fix(database): tests for slash in table name support mysql
Always-prog Jul 26, 2023
4a41ade
fix(databases): added path type to table_name in fetch_datasource_met…
Always-prog Jul 26, 2023
82b0a13
Merge branch 'apache-master' into fix/cannot-create-datasource-with-s…
Always-prog Jul 26, 2023
5a2e89b
pre-commit fix
Always-prog Jul 26, 2023
f1fb99e
fix(databases): removed mySQL from slashes test
Always-prog Jul 26, 2023
c3309a6
ignore sqlite database
Always-prog Jul 26, 2023
930938f
include sqlite and mysql
Always-prog Jul 28, 2023
40569b1
rename test
Always-prog Jul 28, 2023
62d0ebd
fix(datasets): give possibility to add dataset with slashes in name
Always-prog Jul 25, 2023
5a9398f
tests(database): get table details if table has slash in name
Always-prog Jul 26, 2023
59a39f2
fix(chore): added type for table_name in the endpoints
Always-prog Jul 26, 2023
361f600
oops
Always-prog Jul 26, 2023
2bf6c76
fix(database): tests for slash in table name support mysql
Always-prog Jul 26, 2023
43dd9f6
fix(databases): added path type to table_name in fetch_datasource_met…
Always-prog Jul 26, 2023
2396011
pre-commit fix
Always-prog Jul 26, 2023
c156dd7
fix(databases): removed mySQL from slashes test
Always-prog Jul 26, 2023
96dbaef
ignore sqlite database
Always-prog Jul 26, 2023
4849f12
include sqlite and mysql
Always-prog Jul 28, 2023
e96eeef
rename test
Always-prog Jul 28, 2023
ca4b413
Merge branch 'fix/cannot-create-datasource-with-slash-in-name' of htt…
Always-prog Jul 28, 2023
4119ee6
Merge branch 'apache-master' into fix/cannot-create-datasource-with-s…
Always-prog Jul 28, 2023
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
8 changes: 4 additions & 4 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def tables(self, pk: int, **kwargs: Any) -> FlaskResponse:
except DatabaseTablesUnexpectedError as ex:
return self.response_422(ex.message)

@expose("/<int:pk>/table/<table_name>/<schema_name>/", methods=("GET",))
@expose("/<int:pk>/table/<path:table_name>/<schema_name>/", methods=("GET",))
@protect()
@check_datasource_access
@safe
Expand Down Expand Up @@ -735,7 +735,7 @@ def table_metadata(
self.incr_stats("success", self.table_metadata.__name__)
return self.response(200, **table_info)

@expose("/<int:pk>/table_extra/<table_name>/<schema_name>/", methods=("GET",))
@expose("/<int:pk>/table_extra/<path:table_name>/<schema_name>/", methods=("GET",))
@protect()
@check_datasource_access
@safe
Expand Down Expand Up @@ -798,8 +798,8 @@ def table_extra_metadata(
)
return self.response(200, **payload)

@expose("/<int:pk>/select_star/<table_name>/", methods=("GET",))
@expose("/<int:pk>/select_star/<table_name>/<schema_name>/", methods=("GET",))
@expose("/<int:pk>/select_star/<path:table_name>/", methods=("GET",))
@expose("/<int:pk>/select_star/<path:table_name>/<schema_name>/", methods=("GET",))
@protect()
@check_datasource_access
@safe
Expand Down
4 changes: 3 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@ def theme(self) -> FlaskResponse:
@has_access
@event_logger.log_this
@expose("/fetch_datasource_metadata")
@deprecated(new_target="api/v1/database/<int:pk>/table/<table_name>/<schema_name>/")
@deprecated(
new_target="api/v1/database/<int:pk>/table/<path:table_name>/<schema_name>/"
)
def fetch_datasource_metadata(self) -> FlaskResponse:
"""
Fetch the datasource metadata.
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,21 @@ def test_if_ssh_tunneling_flag_is_not_active_it_raises_new_exception(
# the DB should not be created
assert model is None

def test_get_table_details_with_slash_in_name(self):
table_name = "table_with/slash"
database = get_example_database()
if database.backend in ("mysql", "sqlite"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems MySQL and SQLite support table names with slashes but you need to escape them.

return
with database.get_sqla_engine_with_context() as engine:
query = f'CREATE TABLE IF NOT EXISTS "{table_name}" (col VARCHAR(256))'
engine.execute(query)

self.login(username="admin")
uri = f"api/v1/database/{database.id}/table/{table_name}/public/"
rv = self.client.get(uri)

self.assertEqual(rv.status_code, 200)

def test_create_database_invalid_configuration_method(self):
"""
Database API: Test create with an invalid configuration method.
Expand Down
Loading