From 5408c5dbae90057a8fe390b8f42c692a3eb02bcf Mon Sep 17 00:00:00 2001 From: Hex Date: Mon, 2 Feb 2026 07:37:55 -0700 Subject: [PATCH] Fix: Use Annotated syntax for webhook_data Query parameter Fixes #126 The webhook_data parameter in api_lnurl_response() was using Query(None) as a default value. When called directly as a Python function (e.g., from lnaddress()), Query(None) doesn't resolve to None - it remains a FastAPI FieldInfo object which is truthy. This caused malformed callback URLs to be generated with webhook_data=alias%3D%27webhook_data%27+extra%3D%7B%7D appended, breaking LNURL-pay flows (especially Nostr zaps) because clients would append ?amount=... to a URL already containing query parameters, resulting in double question marks. Solution: Use Annotated[str | None, Query()] = None syntax which properly separates FastAPI metadata from the default value, making the function safe to call both via HTTP and directly. This fixes all lightning address zaps that were failing with 400 errors. --- views_lnurl.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/views_lnurl.py b/views_lnurl.py index 475b57f..ed14b22 100644 --- a/views_lnurl.py +++ b/views_lnurl.py @@ -1,5 +1,6 @@ import json from http import HTTPStatus +from typing import Annotated from fastapi import APIRouter, HTTPException, Query, Request from lnbits.core.services import create_invoice @@ -150,7 +151,9 @@ async def api_lnurl_callback( name="lnurlp.api_lnurl_response", ) async def api_lnurl_response( - request: Request, link_id: str, webhook_data: str | None = Query(None) + request: Request, + link_id: str, + webhook_data: Annotated[str | None, Query()] = None, ) -> LnurlPayResponse: link = await get_pay_link(link_id) if not link: