Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ def _get_fastapi_route(fastapi_app: FastAPI, scope) -> Optional[Route]:
# and return the route name if found.
match, child_scope = route.matches(scope)
if match == Match.FULL:
return child_scope["route"]
return child_scope.get("route")
return None
14 changes: 14 additions & 0 deletions python/sqlcommenter-python/tests/fastapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from google.cloud.sqlcommenter.fastapi import (
SQLCommenterMiddleware, get_fastapi_info,
)
from starlette.applications import Starlette
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.routing import Route

app = FastAPI(title="SQLCommenter")

Expand All @@ -28,3 +30,15 @@ async def custom_http_exception_handler(request, exc):
status_code=status.HTTP_404_NOT_FOUND,
content=get_fastapi_info(),
)


def starlette_endpoint(_):
return JSONResponse({"from": "starlette"})


starlette_subapi = Starlette(routes=[
Route("/", starlette_endpoint),
])


app.mount("/starlette", starlette_subapi)
10 changes: 10 additions & 0 deletions python/sqlcommenter-python/tests/fastapi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ def test_get_fastapi_info_in_404_error_context(client):

def test_get_fastapi_info_outside_request_context(client):
assert get_fastapi_info() == {}


def test_get_openapi_does_not_throw_an_error(client):
resp = client.get(app.docs_url)
assert resp.status_code == 200


def test_get_starlette_endpoints_does_not_throw_an_error(client):
resp = client.get("/starlette")
assert resp.status_code == 200