madhushreeag commented on code in PR #43337:
URL: https://github.com/apache/superset/pull/43337#discussion_r3823793794
##########
superset/charts/schemas.py:
##########
@@ -972,21 +979,31 @@ class ChartDataGeodeticParseOptionsSchema(
class ChartDataPostProcessingOperationSchema(Schema):
+ _builtin_ops = pandas_postprocessing.__all__
+
operation = fields.String(
metadata={
"description": "Post processing operation type",
"example": "aggregate",
},
required=True,
- validate=validate.OneOf(
- choices=[
- name
- for name, value in inspect.getmembers(
- pandas_postprocessing, inspect.isfunction
- )
- ]
- ),
)
+
+ @validates("operation")
+ def validate_operation(self, value: str, **kwargs: object) -> None:
+ from flask import current_app
+
+ extra_op_names = list(
+ pandas_postprocessing.build_extra_ops_map(
+ current_app.config.get("EXTRA_PANDAS_POSTPROCESSING_OPS", [])
Review Comment:
@sadpandajoe
Addressed. Two changes:
1. Built-ins short-circuit before any config access - If value in
self._builtin_ops: return. Validating a built-in operation never dereferences
current_app, so the previously-working no-app-context path is restored.
2. Missing context is handled like the neighboring validators. The config
read is wrapped in try/except RuntimeError, matching the existing
get_time_grain_choices and get_max_prophet_periods pattern in the same file.
Outside a context the extra-op list is treated as empty, so an unknown
operation still produces a clean ValidationError rather than a RuntimeError.
One Caveat - The error message outside an app context now lists only
built-ins. That's the same message the code produced before this PR, so it's
not a regression, but it does mean a spec-generation context won't advertise
operator-registered ops.
--
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]