Skip to content

[BUG]: POST /api/weblinks/upload always returns 500 — WebLinkCapture.submit_url() rejects the filename_hint argument the route passes #374

Description

@Linxiushen

What happened

Every request to POST /api/weblinks/upload fails with a generic {"code":500,"status":500,"message":"Internal server error"}, with or without filename_hint in the body.

opencontext/server/routes/documents.py::upload_weblink() calls

ok = component.submit_url(request.url, request.filename_hint)

but WebLinkCapture.submit_url() (opencontext/context_capture/web_link_capture.py) is declared as def submit_url(self, url: str), so the call raises

TypeError: WebLinkCapture.submit_url() takes 2 positional arguments but 3 were given

which the route's blanket except Exception turns into the 500 above. Both were added together in #289, and the endpoint has no caller in the frontend, so it never worked.

Reproduction

FastAPI TestClient against the real documents.py router + real ContextCaptureManager + real WebLinkCapture (only the server god-object stubbed):

payload={'url': 'https://example.com/', 'filename_hint': 'example'}
  -> HTTP 500 {"code":500,"status":500,"message":"Internal server error"}
  -> swallowed TypeError: WebLinkCapture.submit_url() takes 2 positional arguments but 3 were given
     at opencontext/server/routes/documents.py, line 90, in upload_weblink
payload={'url': 'https://example.com/'}
  -> HTTP 500 (same TypeError; the route passes filename_hint positionally even when it is None)

Expected behaviour

submit_url() accepts the filename_hint the route already sends and threads it through to convert_url_to_markdown() / convert_url_to_pdf(), which already take a filename_hint parameter — so the requested output filename is honoured instead of the endpoint crashing.

Note for whoever picks this up: after the signature fix, a stock install in the default markdown mode still answers 400 "Failed to queue URL" because the markdown path imports crawl4ai, which is not in pyproject.toml's dependencies (the log then says pip install crawl4ai); the pdf mode (playwright, declared) works end to end.

I have a small fix with unit tests ready and will open a PR referencing this issue.

(Found and verified with Claude Code, AI-assisted.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions