mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix missing series validation not raised an exception (#16946)
This commit is contained in:
parent
0d0c759cfe
commit
c05c6b3db4
@ -14,6 +14,7 @@
|
|||||||
# KIND, either express or implied. See the License for the
|
# KIND, either express or implied. See the License for the
|
||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
# pylint: disable=invalid-name
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List, NamedTuple, Optional, TYPE_CHECKING
|
from typing import Any, Dict, List, NamedTuple, Optional, TYPE_CHECKING
|
||||||
@ -273,28 +274,37 @@ class QueryObject: # pylint: disable=too-many-instance-attributes
|
|||||||
self, raise_exceptions: Optional[bool] = True
|
self, raise_exceptions: Optional[bool] = True
|
||||||
) -> Optional[QueryObjectValidationError]:
|
) -> Optional[QueryObjectValidationError]:
|
||||||
"""Validate query object"""
|
"""Validate query object"""
|
||||||
error: Optional[QueryObjectValidationError] = None
|
try:
|
||||||
all_labels = self.metric_names + self.column_names
|
self._validate_there_are_no_missing_series()
|
||||||
missing_series = [col for col in self.series_columns if col not in self.columns]
|
self._validate_no_have_duplicate_labels()
|
||||||
if missing_series:
|
return None
|
||||||
_(
|
except QueryObjectValidationError as ex:
|
||||||
"The following entries in `series_columns` are missing "
|
if raise_exceptions:
|
||||||
"in `columns`: %(columns)s. ",
|
raise ex
|
||||||
columns=", ".join(f'"{x}"' for x in missing_series),
|
return ex
|
||||||
)
|
|
||||||
|
|
||||||
|
def _validate_no_have_duplicate_labels(self) -> None:
|
||||||
|
all_labels = self.metric_names + self.column_names
|
||||||
if len(set(all_labels)) < len(all_labels):
|
if len(set(all_labels)) < len(all_labels):
|
||||||
dup_labels = find_duplicates(all_labels)
|
dup_labels = find_duplicates(all_labels)
|
||||||
error = QueryObjectValidationError(
|
raise QueryObjectValidationError(
|
||||||
_(
|
_(
|
||||||
"Duplicate column/metric labels: %(labels)s. Please make "
|
"Duplicate column/metric labels: %(labels)s. Please make "
|
||||||
"sure all columns and metrics have a unique label.",
|
"sure all columns and metrics have a unique label.",
|
||||||
labels=", ".join(f'"{x}"' for x in dup_labels),
|
labels=", ".join(f'"{x}"' for x in dup_labels),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if error and raise_exceptions:
|
|
||||||
raise error
|
def _validate_there_are_no_missing_series(self) -> None:
|
||||||
return error
|
missing_series = [col for col in self.series_columns if col not in self.columns]
|
||||||
|
if missing_series:
|
||||||
|
raise QueryObjectValidationError(
|
||||||
|
_(
|
||||||
|
"The following entries in `series_columns` are missing "
|
||||||
|
"in `columns`: %(columns)s. ",
|
||||||
|
columns=", ".join(f'"{x}"' for x in missing_series),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
query_object_dict = {
|
query_object_dict = {
|
||||||
|
Loading…
Reference in New Issue
Block a user