Fix spurious "Too many arguments provided for the endpoint" warnings
Browse filesRoot-caused via the actual gradio 5.25.0 source (matching the deployed
version exactly): Blocks.get_api_info() never populates the
unnamed_endpoints dict (confirmed still true in 5.50.0 and 6.20.0 too
— named_endpoints gets every dependency, unnamed_endpoints is just
never written to). But the JS client dispatches every internal
click/change/upload event by numeric fn_index and looks it up
specifically in unnamed_endpoints, so endpoint_info is always
undefined for these, parameters falls back to [], and any non-empty
data array trips a false-positive "too many arguments" warning. This
never actually broke anything (map_data_to_params just falls back to
the raw args on the empty-parameters path), but it fired on every
video upload and every Generate click in both live repro sessions.
Fix: monkeypatch get_api_info to mirror each already-computed
named_endpoints entry into unnamed_endpoints under its numeric
fn_index, since every dependency already gets an auto-generated
api_name regardless. Verified against the real gradio==5.25.0 package
in an isolated venv, including the duplicate-fn-registration pattern
this app uses (_on_video_upload_taro registered 3x) — every fn_index
resolves to its own correctly-sized parameter list post-patch.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@@ -56,6 +56,35 @@ def _patched_convert_video_to_playable_mp4(video_path: str) -> str:
|
|
| 56 |
|
| 57 |
_gr_processing_utils.convert_video_to_playable_mp4 = _patched_convert_video_to_playable_mp4
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# ================================================================== #
|
| 60 |
# CHECKPOINT CONFIGURATION #
|
| 61 |
# ================================================================== #
|
|
|
|
| 56 |
|
| 57 |
_gr_processing_utils.convert_video_to_playable_mp4 = _patched_convert_video_to_playable_mp4
|
| 58 |
|
| 59 |
+
# ------------------------------------------------------------------ #
|
| 60 |
+
# Gradio 5.x/6.x's Blocks.get_api_info() always returns an empty #
|
| 61 |
+
# unnamed_endpoints dict (confirmed still true through 5.50.0 and #
|
| 62 |
+
# 6.20.0 — it's simply never populated). But the JS client dispatches #
|
| 63 |
+
# every internal (non-api_name) click/change/upload event by numeric #
|
| 64 |
+
# fn_index, and looks that fn_index up in exactly that always-empty #
|
| 65 |
+
# dict, so endpoint_info resolves to undefined and every such event #
|
| 66 |
+
# logs a harmless "Too many arguments provided for the endpoint." #
|
| 67 |
+
# console warning (it doesn't drop data or block the request — see #
|
| 68 |
+
# gradio's client/src/helpers/api_info.ts map_data_to_params, which #
|
| 69 |
+
# just falls back to the raw args array). Since every dependency #
|
| 70 |
+
# already gets an auto-generated api_name and a fully-computed entry #
|
| 71 |
+
# in named_endpoints regardless, just mirror each of those into #
|
| 72 |
+
# unnamed_endpoints keyed by its numeric fn_index so the JS client's #
|
| 73 |
+
# lookup actually finds it. #
|
| 74 |
+
_orig_get_api_info = gr.Blocks.get_api_info
|
| 75 |
+
|
| 76 |
+
def _patched_get_api_info(self, all_endpoints: bool = False):
|
| 77 |
+
api_info = _orig_get_api_info(self, all_endpoints=all_endpoints)
|
| 78 |
+
for fn_index, fn in self.fns.items():
|
| 79 |
+
if not fn.fn or fn.api_name is False:
|
| 80 |
+
continue
|
| 81 |
+
entry = api_info["named_endpoints"].get(f"/{fn.api_name}")
|
| 82 |
+
if entry is not None:
|
| 83 |
+
api_info["unnamed_endpoints"][str(fn_index)] = entry
|
| 84 |
+
return api_info
|
| 85 |
+
|
| 86 |
+
gr.Blocks.get_api_info = _patched_get_api_info
|
| 87 |
+
|
| 88 |
# ================================================================== #
|
| 89 |
# CHECKPOINT CONFIGURATION #
|
| 90 |
# ================================================================== #
|