rusackas commented on code in PR #44549:
URL: https://github.com/apache/superset/pull/44549#discussion_r4083024377


##########
superset/utils/schema.py:
##########
@@ -56,6 +56,54 @@ 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 -- 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
+    datasource = value.get("datasource")
+    return (
+        isinstance(datasource, dict)
+        and bool(datasource.get("id"))
+        and bool(datasource.get("type"))

Review Comment:
   Good catch, added a check that `type` is a valid `DatasourceType` member 
instead of just present.



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