-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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: change the validation logic for python_date_format #25510
Changes from 15 commits
c4d70e4
0108456
0cb09cc
7c7210f
2f05b7f
4c849e2
dfb55e1
ff6ca17
baae852
a6fa404
0f320a8
6f697c5
cefc744
e6f8e26
7f3055a
20e484e
6aee27c
0269e95
94b1482
b5ca468
daf90cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ | |
from __future__ import annotations | ||
|
||
import logging | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
import dateutil.parser | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn | ||
|
@@ -150,6 +152,17 @@ def validate_metrics_uniqueness(dataset_id: int, metrics_names: list[str]) -> bo | |
).all() | ||
return len(dataset_query) == 0 | ||
|
||
@staticmethod | ||
def validate_column_pdf_is_iso8601(dt_format: str) -> bool: | ||
if dt_format in ("epoch_s", "epoch_ms", None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this logic is somewhat duplicated in three places? Can this be refactored into a helper method if neither the model nor the DAO seems appropriate for both cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TableColumn insert/update using bulk_insert_mappings or bulk_update_mappings does not trigger the ORM's |
||
return True | ||
try: | ||
dt_str = datetime.now().strftime(dt_format) | ||
dateutil.parser.isoparse(dt_str) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
@classmethod | ||
def update( | ||
cls, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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. | ||
|
||
# pylint: disable=import-outside-toplevel, invalid-name, unused-argument, redefined-outer-name | ||
import pytest | ||
from marshmallow import ValidationError | ||
|
||
from superset.datasets.schemas import validate_python_date_format | ||
|
||
|
||
# pylint: disable=too-few-public-methods | ||
@pytest.mark.parametrize( | ||
"payload", | ||
[ | ||
"epoch_ms", | ||
"epoch_s", | ||
"%Y-%m-%dT%H:%M:%S.%f", | ||
"%Y%m%d", | ||
], | ||
) | ||
def test_validate_python_date_format(payload) -> None: | ||
assert validate_python_date_format(payload) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"payload", | ||
[ | ||
"%d%m%Y", | ||
"%Y/%m/%dT%H:%M:%S.%f", | ||
], | ||
) | ||
def test_validate_python_date_format_raises(payload) -> None: | ||
with pytest.raises(ValidationError): | ||
validate_python_date_format(payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand by @john-bodley's comment, this won't be a breaking change. If that's the case, this should be moved to the Next section and the text should be changed given that: