fix(usage): populate lago_invoice_id on customer usage responses - #408
Merged
vincent-pochet merged 1 commit intoJul 21, 2026
Merged
Conversation
The Lago API returns the invoice identifier under `lago_invoice_id`, but `CustomerUsageResponse` declared it as `invoice_id`. Because pydantic drops unknown fields by default, the value was silently discarded and the field was always null. Rename the field to `lago_invoice_id` to match the API payload (same fix applied to `WalletTransactionResponse` in getlago#379), affecting both the `current_usage` and `past_usage` endpoints. Update the current-usage fixture and add assertions covering the field. Fixes getlago#407 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Welcome, @ayush-sharaf!Thanks for your first contribution! Before we proceed with the review, please sign the Fiduciary License Agreement: Once signed, this PR will be automatically updated. |
Thanks, @ayush-sharaf! 🎉Your CLA has been signed and is now on file. We'll proceed with the review shortly. |
vincent-pochet
approved these changes
Jul 21, 2026
Contributor
|
Thank you @ayush-sharaf for this fix, it looks good. |
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.
Problem
CustomerUsageResponsedeclares aninvoice_idfield, but the Lago API returns the invoice identifier under the keylago_invoice_id. Since pydantic drops unknown fields by default, the API value is silently discarded during deserialization, leaving the field permanentlynull.This affects both the
current_usageandpast_usageendpoints. Forpast_usagein particular, this field is the only mechanism to associate a closed billing period with its invoice, so the bug makes that association impossible.The mismatch is visible in the existing fixture
tests/fixtures/customer_past_usage.json, which already containslago_invoice_idwhile the model expectedinvoice_id.I verified this against the serializers in
getlago/lago-api. All three usage serializers emitlago_invoice_id, neverinvoice_id:current_usageUsageSerializernil(hardcoded)past_usagePastUsageSerializerinvoice.id(real UUID)projected_usageProjectedUsageSerializernil(hardcoded)So
past_usageis the endpoint that was actually losing data — the server returns a real invoice id that the client silently dropped.current_usagereturnsnilserver-side by design, so it will keep deserializing asNone, but now as an intentional, contract-matching field rather than a phantom one.Fixes #407
Fix
Rename the field
invoice_id→lago_invoice_idonCustomerUsageResponseto match the API payload. This mirrors the fix applied toWalletTransactionResponsein #379.Changes
lago_python_client/models/customer_usage.py: renameinvoice_id→lago_invoice_id.tests/fixtures/customer_usage.json: update the current-usage fixture key tolago_invoice_id.tests/test_customer_client.py: assertlago_invoice_idis populated forpast_usageand present (null) forcurrent_usage.Testing
pytest tests/test_customer_client.py— 14 passed.Note
CustomerProjectedUsageResponse(theprojected_usageendpoint) has the sameinvoice_idkey mismatch, but per the backend (ProjectedUsageSerializer) the value is hardcoded tonil— so it's a cosmetic/contract-consistency mismatch with no lost data, unlikepast_usage. It's outside the scope of #407, so I left it unchanged here; happy to fold in the rename for consistency if you'd like.🤖 Generated with Claude Code