Compare commits

..
Author SHA1 Message Date
Joe Li 6555936709 fix(ci): repair scheduled pre-commit drift 2026-08-27 09:32:29 -07:00
11 changed files with 9 additions and 139 deletions
@@ -21,6 +21,7 @@ from abc import ABC, abstractmethod
from typing import Any, Generic, TypeVar
from pydantic import BaseModel
from superset_core.semantic_layers.view import SemanticView
ConfigT = TypeVar("ConfigT", bound=BaseModel)
@@ -312,7 +312,7 @@ export function handleComponentDrop(dropResult: DropResult) {
source &&
!(
// ensure it has moved
(destination.id === source.id && destination.index === source.index)
destination.id === source.id && destination.index === source.index
)
) {
dispatch(moveComponent(dropResult));
+1 -1
View File
@@ -126,7 +126,7 @@ function fillNativeFilters(
!(
// Treat all-null arrays (range filters use [null, null] as their
// canonical cleared value) and empty arrays as "no value".
(Array.isArray(loadedValue) && loadedValue.every(v => v === null))
Array.isArray(loadedValue) && loadedValue.every(v => v === null)
);
const loadedHasExtraFormData =
!!loaded?.extraFormData && Object.keys(loaded.extraFormData).length > 0;
@@ -29,7 +29,9 @@ import { ControlFormItemComponents } from './ControlForm';
* Column formatting configs.
*/
export type ColumnConfig = {
[key in SharedColumnConfigProp]?: (typeof SHARED_COLUMN_CONFIG_PROPS)[key]['value'];
[
key in SharedColumnConfigProp
]?: (typeof SHARED_COLUMN_CONFIG_PROPS)[key]['value'];
} & Record<string, StrictJsonValue>;
/**
@@ -18,13 +18,11 @@ import logging
from functools import partial
from typing import Any, Optional
from jinja2.exceptions import TemplateError
from sqlalchemy.exc import SQLAlchemyError
from superset import db
from superset.commands.explore.permalink.base import BaseExplorePermalinkCommand
from superset.daos.key_value import KeyValueDAO
from superset.exceptions import SupersetTemplateException
from superset.explore.permalink.exceptions import ExplorePermalinkCreateFailedError
from superset.explore.utils import check_access as check_chart_access
from superset.key_value.exceptions import (
@@ -60,10 +58,7 @@ class CreateExplorePermalinkCommand(BaseExplorePermalinkCommand):
d_id, d_type = self.datasource.split("__")
datasource_id = int(d_id)
datasource_type = DatasourceType(d_type)
try:
check_chart_access(datasource_id, self.chart_id, datasource_type)
except TemplateError as ex:
raise SupersetTemplateException(str(ex)) from ex
check_chart_access(datasource_id, self.chart_id, datasource_type)
value = {
"chartId": self.chart_id,
"datasourceId": datasource_id,
+1 -6
View File
@@ -17,13 +17,11 @@
import logging
from typing import Optional
from jinja2.exceptions import TemplateError
from sqlalchemy.exc import SQLAlchemyError
from superset.commands.dataset.exceptions import DatasetNotFoundError
from superset.commands.explore.permalink.base import BaseExplorePermalinkCommand
from superset.daos.key_value import KeyValueDAO
from superset.exceptions import SupersetTemplateException
from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError
from superset.explore.permalink.types import ExplorePermalinkValue
from superset.explore.utils import check_access as check_chart_access
@@ -56,10 +54,7 @@ class GetExplorePermalinkCommand(BaseExplorePermalinkCommand):
datasource_type = DatasourceType(
value.get("datasourceType", DatasourceType.TABLE)
)
try:
check_chart_access(datasource_id, chart_id, datasource_type)
except TemplateError as ex:
raise SupersetTemplateException(str(ex)) from ex
check_chart_access(datasource_id, chart_id, datasource_type)
return value
return None
except (
-5
View File
@@ -31,7 +31,6 @@ from superset.commands.dataset.exceptions import (
from superset.commands.explore.permalink.create import CreateExplorePermalinkCommand
from superset.commands.explore.permalink.get import GetExplorePermalinkCommand
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP
from superset.exceptions import SupersetTemplateException
from superset.explore.permalink.exceptions import ExplorePermalinkInvalidStateError
from superset.explore.permalink.schemas import ExplorePermalinkStateSchema
from superset.extensions import event_logger
@@ -108,8 +107,6 @@ class ExplorePermalinkRestApi(BaseSupersetApi):
return self.response(403, message=str(ex))
except (ChartNotFoundError, DatasetNotFoundError) as ex:
return self.response(404, message=str(ex))
except SupersetTemplateException as ex:
return self.response(ex.status, message=str(ex))
@expose("/permalink/<string:key>", methods=("GET",))
@protect()
@@ -165,5 +162,3 @@ class ExplorePermalinkRestApi(BaseSupersetApi):
return self.response(403, message=str(ex))
except (ChartNotFoundError, DatasetNotFoundError) as ex:
return self.response(404, message=str(ex))
except SupersetTemplateException as ex:
return self.response(ex.status, message=str(ex))
+1 -1
View File
@@ -404,7 +404,7 @@ class SemanticView(AuditMixinNullable, Model):
for dimension in dimensions
},
}
column_formats = {
column_formats: dict[str, str | None] = {
metric.name: metric.d3format for metric in metrics if metric.d3format
}
@@ -1,16 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
@@ -1,45 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from unittest.mock import patch
import pytest
from jinja2.exceptions import TemplateError, TemplateSyntaxError
from superset.commands.explore.permalink.create import CreateExplorePermalinkCommand
from superset.exceptions import SupersetTemplateException
check_chart_access = "superset.commands.explore.permalink.create.check_chart_access"
def test_create_permalink_malformed_jinja_template() -> None:
# ``check_chart_access`` funnels into ``raise_for_access`` which re-parses the
# query's unrendered Jinja via ``process_jinja_sql`` and can raise a raw
# ``TemplateError`` (e.g. an unclosed ``{% if %}``). ``TemplateSyntaxError`` is
# a subclass of ``TemplateError``. It must surface as a
# ``SupersetTemplateException`` (422), not propagate as an opaque 500.
assert issubclass(TemplateSyntaxError, TemplateError)
command = CreateExplorePermalinkCommand(
{"formData": {"datasource": "1__table", "slice_id": 1}}
)
with patch(
check_chart_access,
side_effect=TemplateSyntaxError("unexpected end of template", lineno=1),
):
with pytest.raises(SupersetTemplateException):
command.run()
@@ -1,57 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from unittest.mock import patch
import pytest
from jinja2.exceptions import TemplateError, TemplateSyntaxError
from superset.commands.explore.permalink.get import GetExplorePermalinkCommand
from superset.exceptions import SupersetTemplateException
from superset.utils.core import DatasourceType
check_chart_access = "superset.commands.explore.permalink.get.check_chart_access"
decode_permalink_id = "superset.commands.explore.permalink.get.decode_permalink_id"
get_value = "superset.daos.key_value.KeyValueDAO.get_value"
def test_get_permalink_malformed_jinja_template() -> None:
# ``check_chart_access`` funnels into ``raise_for_access`` which re-parses the
# query's unrendered Jinja via ``process_jinja_sql`` and can raise a raw
# ``TemplateError`` (e.g. an unclosed ``{% if %}``). ``TemplateSyntaxError`` is
# a subclass of ``TemplateError``. It must surface as a
# ``SupersetTemplateException`` (422), not propagate as an opaque 500.
assert issubclass(TemplateSyntaxError, TemplateError)
command = GetExplorePermalinkCommand("thisisallmocked")
with (
patch(decode_permalink_id, return_value="123456"),
patch(
get_value,
return_value={
"chartId": 1,
"datasourceId": 1,
"datasourceType": DatasourceType.TABLE.value,
},
),
patch(
check_chart_access,
side_effect=TemplateSyntaxError("unexpected end of template", lineno=1),
),
):
with pytest.raises(SupersetTemplateException):
command.run()