codeant-ai-for-open-source[bot] commented on code in PR #46037: URL: https://github.com/apache/superset/pull/46037#discussion_r4482554095
########## superset/dashboards/refresh_policy.py: ########## @@ -0,0 +1,328 @@ +# 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. +"""Server-side checks for a dashboard's ``auto_refresh_policy``.""" + +from __future__ import annotations + +import math +import re +from dataclasses import dataclass +from typing import Any + +from flask import current_app +from flask_babel import gettext as __, ngettext +from flask_babel.speaklater import LazyString + +from superset import is_feature_enabled +from superset.utils import json + +POLICY_KEY = "auto_refresh_policy" +MIN_KEY = "minimum_refresh_interval" +MAX_KEY = "maximum_refresh_interval" +SWITCH_KEYS = ("auto_refresh_allowed", "custom_refresh_allowed") +BOUND_KEYS = (MIN_KEY, MAX_KEY) +UNIT_SECONDS = {"seconds": 1, "minutes": 60, "hours": 3600} + +DEFAULT_REFRESH_INTERVALS: list[float] = [ + 0, + 10, + 30, + 60, + 300, + 1800, + 3600, + 21600, + 43200, + 86400, +] + +_DECIMAL = re.compile(r"[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?", re.ASCII) +_PREFIXED = { + re.compile(r"0[xX][0-9a-fA-F]+"): 16, + re.compile(r"0[oO][0-7]+"): 8, + re.compile(r"0[bB][01]+"): 2, +} + + +@dataclass(frozen=True) +class RefreshPolicyError: + """A field-level policy validation failure.""" + + field: str + code: str + message: str + + +def _to_seconds(value: Any) -> float | None: + """Mirror of JS ``Number()`` for the value types the frontend accepts.""" + if isinstance(value, bool): + return None + if isinstance(value, (int, float)): + seconds = float(value) Review Comment: ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved** as of `b91d79a`. `_to_seconds` now catches `OverflowError` from `float(value)` and returns `None` for values that cannot be converted. <sub>If that's not right, unresolve this thread and CodeAnt will leave it open.</sub> <!-- codeant-auto-resolve-reply --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
