Claude commited on
Commit
6e8f79b
·
unverified ·
1 Parent(s): 287f104

Patch `_json_schema_to_python_type` too, not just `get_type`

Browse files

Last commit wrapped `get_type`, but the crash is in
`_json_schema_to_python_type` itself — when it recurses into
`schema['additionalProperties']` (which is `True`), the function has no
branch for non-dict input and raises `APIInfoParseError: Cannot parse
schema True` before `get_type` is ever reached.

Wrap the walker too: return "Any" when fed a bool at any recursion
level. Verified locally against the exact shape from the Space log.

Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -30,21 +30,30 @@ _SRC = Path(__file__).resolve().parent / "src"
30
  if _SRC.is_dir() and str(_SRC) not in sys.path:
31
  sys.path.insert(0, str(_SRC))
32
 
33
- # gradio 4.44.0 has a bug in `gradio_client.utils.get_type` that crashes when
34
- # a sub-schema is a bool (`additionalProperties: False`) — fixed in 4.44.1,
35
- # but HF Spaces pins 4.44.0. Wrap the function so bool schemas return "Any"
36
- # instead of raising "argument of type 'bool' is not iterable" on every page
37
- # load.
 
 
38
  try:
39
  from gradio_client import utils as _gc_utils
40
 
 
41
  _orig_get_type = _gc_utils.get_type
42
 
 
 
 
 
 
43
  def _safe_get_type(schema):
44
  if not isinstance(schema, dict):
45
  return "Any"
46
  return _orig_get_type(schema)
47
 
 
48
  _gc_utils.get_type = _safe_get_type
49
  except Exception: # noqa: BLE001 — best-effort; don't block startup
50
  pass
 
30
  if _SRC.is_dir() and str(_SRC) not in sys.path:
31
  sys.path.insert(0, str(_SRC))
32
 
33
+ # gradio 4.44.0 crashes on every page load when a JSON sub-schema is a bool
34
+ # (JSON Schema draft 2020-12 allows `additionalProperties: True|False`, and
35
+ # pydantic emits it). Fixed in 4.44.1, but HF Spaces pins 4.44.0 in its
36
+ # build bootstrap. Wrap both the schema walker and the type dispatcher so
37
+ # bool schemas degrade to "Any" instead of raising APIInfoParseError.
38
+ # Recursion inside gradio_client.utils resolves these names via module
39
+ # globals, so patching the module attributes intercepts every call site.
40
  try:
41
  from gradio_client import utils as _gc_utils
42
 
43
+ _orig_walk = _gc_utils._json_schema_to_python_type
44
  _orig_get_type = _gc_utils.get_type
45
 
46
+ def _safe_walk(schema, defs=None):
47
+ if isinstance(schema, bool):
48
+ return "Any"
49
+ return _orig_walk(schema, defs)
50
+
51
  def _safe_get_type(schema):
52
  if not isinstance(schema, dict):
53
  return "Any"
54
  return _orig_get_type(schema)
55
 
56
+ _gc_utils._json_schema_to_python_type = _safe_walk
57
  _gc_utils.get_type = _safe_get_type
58
  except Exception: # noqa: BLE001 — best-effort; don't block startup
59
  pass