Fix: Use Annotated syntax for webhook_data Query parameter#127
Open
hexdaemon wants to merge 1 commit intolnbits:mainfrom
Open
Fix: Use Annotated syntax for webhook_data Query parameter#127hexdaemon wants to merge 1 commit intolnbits:mainfrom
hexdaemon wants to merge 1 commit intolnbits:mainfrom
Conversation
Fixes lnbits#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126
Problem
When accessing a lightning address via , the returned callback URL contains a malformed parameter even when no webhook is configured. This breaks LNURL-pay flows (especially Nostr zaps) because clients append to a URL that already has query parameters, resulting in double question marks.
Root Cause
The parameter in was using as a default value. When called directly as a Python function (from ), doesn't resolve to - it remains a FastAPI object which is truthy.
This caused the check
if webhook_data:to pass, appending the string representation of the FieldInfo object to the callback URL.Solution
Use
Annotated[str | None, Query()] = Nonesyntax which properly separates FastAPI metadata from the default value, making the function safe to call both via HTTP and directly as a Python function.Changes
from typing import AnnotatedimportImpact
Testing
Tested against the exact scenario described in #126: