Skip to content

fastapi openapi utils.py UserWarning: Duplicate Operation ID for function #56

Open

Description

@ctengel

likely due to

Multiple Methods on One Route: Using @app.api_route() with multiple methods (e.g., ["GET", "POST"]) can sometimes cause the generator to produce the same ID for both methods in older FastAPI versions.

apparently FastAPI 0.111.0+ has fixes around deterministic ID generation in these cases.

Activity

  1. ctengel commented on May 22, 2026

    @ctengel
    OwnerAuthor

    Status: deferred — upstream FastAPI bug

    The warnings come from FastAPI's generate_unique_id() not distinguishing between methods when multiple are combined in a single api_route call. Both object_server.py and locator_api.py use @app.api_route("/{bucket}/{key}", methods=['GET', 'HEAD']), which triggers:

    UserWarning: Duplicate Operation ID get_object__bucket___key__head for function get_object
    UserWarning: Duplicate Operation ID find_object__bucket___key__head for function find_object
    

    Option A — Wait for an upstream FastAPI fix

    Tracked in FastAPI issues #4740 and #13175. Fix attempts:

    • PR #4851 — declined; maintainers consider multi-method api_route unsupported
    • PR #10694 — stale with merge conflicts
    • PR #15398 — open as of 2026-04-21, not yet merged

    All released versions through 0.136.1 still emit the warning; upgrading alone won't help.

    Option B — Fix on our end

    Replace the combined api_route with stacked decorators and explicit operation_id values matching openapi.yaml:

    # Before (object_server.py line 119, locator_api.py line 51):
    @app.api_route("/{bucket}/{key}", methods=['GET', 'HEAD'])
    
    # After:
    @app.get("/{bucket}/{key}", operation_id="getObject")
    @app.head("/{bucket}/{key}", operation_id="headObject")

    No function body changes needed. FileResponse and RedirectResponse already strip the body for HEAD responses via Starlette. Warnings disappear and operation IDs align with the hand-maintained spec.

    Decision: defer and watch FastAPI #15398. Revisit if it merges or if warnings start blocking tests.

  2. added
    bugSomething isn't working
    help wantedExtra attention is needed
    on May 28, 2026
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

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions