-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Provide more inclusive error handling for saved queries
- Loading branch information
1 parent
4fce940
commit a8b35e1
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from flask_appbuilder import Model | ||
from jinja2.exceptions import TemplateError | ||
from pytest_mock import MockFixture | ||
|
||
from superset.exceptions import SupersetSecurityException | ||
from superset.models.sql_lab import Query, SavedQuery, SqlTablesMixin | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"klass", | ||
[ | ||
Query, | ||
SavedQuery, | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"exception", | ||
[ | ||
SupersetSecurityException, | ||
TemplateError, | ||
] | ||
) | ||
def test_sql_tables_mixin_sql_tables_exception( | ||
klass: type[Model], | ||
exception: type[Exception], | ||
mocker: MockFixture, | ||
) -> None: | ||
mocker.patch( | ||
"superset.models.sql_lab.extract_tables_from_jinja_sql", | ||
side_effect=TemplateError(), | ||
) | ||
|
||
assert klass(sql="SELECT 1", database=MagicMock()).sql_tables == [] |