aminghadersohi commented on code in PR #44549:
URL: https://github.com/apache/superset/pull/44549#discussion_r4263864398
##########
superset/utils/schema.py:
##########
@@ -56,6 +57,61 @@ def validate_json(value: Union[bytes, bytearray, str]) ->
None:
raise ValidationError("JSON not valid") from ex
+def is_query_context_metadata_complete(value: Any) -> bool:
+ """
+ Whether a parsed ``query_context`` payload carries the ``datasource`` and
+ ``queries`` keys ``QueryContextFactory.create()`` requires (apache/superset
+ #35774): both are required keyword-only arguments there, and a chart saved
+ without them fails every subsequent read with a raw ``TypeError`` instead
+ of a clear error at save time. ``datasource`` must be a mapping carrying
+ the ``id``/``type`` keys ``DatasourceDict`` requires --
``_convert_to_model``
+ indexes both directly and raises ``KeyError`` if either is absent, and
+ passes ``type`` straight to ``DatasourceType(...)``, which raises
+ ``ValueError`` for a value outside that enum -- but ``queries`` may
+ legitimately be an empty list (a chart with no query objects yet still
+ round-trips through ``create()`` without error), so only its presence as
+ a list is checked, not its truthiness.
+
+ :param value: the object obtained by JSON-decoding a query_context string
+ """
+ if not isinstance(value, dict) or not isinstance(value.get("queries"),
list):
+ return False
Review Comment:
Elements unchecked: `queries: ["x"]`/`[null]` still raises the raw TypeError
on read.
```suggestion
if not isinstance(value, dict) or not isinstance(value.get("queries"),
list):
return False
if not all(isinstance(query, dict) for query in value["queries"]):
return False
```
--
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]