Copilot commented on code in PR #40640:
URL: https://github.com/apache/superset/pull/40640#discussion_r3337904838


##########
superset/charts/schemas.py:
##########
@@ -62,6 +62,34 @@ def get_time_grain_choices() -> Any:
     ]
 
 
+# Fallback upper bound for the number of Prophet forecast periods when the
+# application config cannot be read (for example, outside of an app context).
+DEFAULT_MAX_PROPHET_PERIODS = 10000
+
+
+def get_max_prophet_periods() -> int:
+    """Get the configured upper bound for Prophet forecast periods."""
+    try:
+        return current_app.config.get(
+            "MAX_PROPHET_PERIODS", DEFAULT_MAX_PROPHET_PERIODS
+        )
+    except RuntimeError:
+        # Outside app context, fall back to the default bound
+        return DEFAULT_MAX_PROPHET_PERIODS
+
+
+def validate_prophet_periods(value: int) -> None:
+    """Ensure the number of Prophet forecast periods stays within bounds."""
+    Range(
+        min=1,
+        max=get_max_prophet_periods(),
+        error=_(
+            "`periods` must be between 1 and %(max)s",
+            max=get_max_prophet_periods(),
+        ),
+    )(value)

Review Comment:
   `validate_prophet_periods` calls `get_max_prophet_periods()` twice, which is 
redundant and can lead to inconsistencies if the config changes between calls 
(the Range max and the rendered error message could diverge). Capture the 
configured max once and reuse it for both the validator and error message.



-- 
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]

Reply via email to