Preserve a fractional quantity when updating a limit period - #93
Open
thomasbergernz wants to merge 1 commit into
Open
thomasbergernz wants to merge 1 commit into
thomasbergernz wants to merge 1 commit into
Conversation
int(old_period["quantity"]) truncates a fractional value to 0, so a limit change on a component previously set to, say, 0.1 is billed as though the old limit had been nothing: the old period is re-serialised with quantity 0 and the prorated total for that sub-period is lost. Keep the value JSON-native rather than coercing to Decimal. It is written straight back into details["resource_limit_periods"] by serialize_resource_limit_period, and a Decimal is not JSON encodable. Whole numbers stay int, so existing payloads are byte-identical. This is the sibling of the coercion added in 595327d for the total-period diff; that one fixed the TypeError, this one fixes a silent wrong value on the monthly/quarterly/annual path.
This was referenced Sep 7, 2026
Author
|
Context for sequencing: this is the billing-correctness half. The two PRs that make a fractional limit reachable by a customer are #94 (API) and waldur/waldur-homeport#105 (UI). This one and 595327d should land first — otherwise widening the inputs turns a hard error into a quietly wrong invoice. |
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
_update_invoice_itemtruncates the previous period's quantity:So a limit change on a component previously set to a fractional value — say 0.1 TiB — is billed as though the old limit had been nothing. The old sub-period is re-serialised with
quantity: 0, and its prorated share of the billing period is lost frominvoice_item.quantity.Unlike the
set_limits500 fixed in 595327d, this one is silent: the request succeeds and the invoice is quietly wrong, which makes it the harder of the two to notice.Change
Kept JSON-native rather than coerced to
Decimal, because the value goes straight back intodetails["resource_limit_periods"]viaserialize_resource_limit_periodand aDecimalis not JSON encodable. Whole numbers stayint, so existing payloads are byte-identical and integer-only deployments see no change at all.Relationship to 595327d
595327d (
Coerce fractional limits to Decimal in total-period billing [#349]) fixed thefloat - DecimalTypeErroron the TOTAL path — thank you, that came from #91. This is its sibling on the monthly/quarterly/annual path, which that commit did not touch. Both are needed before a fractional limit is safe end to end.For reference, the fix is on
developbut not in8.1.3-rc.8, which still carries both this truncation and the pre-fix subtraction.Verified
Built on 8.1.2 with this change plus the coercion, and run in a test deployment. Changing a
storage_projectlimit from 0.1 to 0.5 on a resource that already had invoice items produced the correct pair of items —0.1 @ 420 = 42.00and a delta of0.4 @ 420 = 168.00, netting 210.00 for 0.5 TiB — where before it raised, and with only the coercion the old period would have contributed 0.Licensing: I agree to license this contribution under the MIT license.