Refactor: select price fields for currency validation by type (PriceField)#2311
Open
Flix6x wants to merge 2 commits into
Open
Refactor: select price fields for currency validation by type (PriceField)#2311Flix6x wants to merge 2 commits into
Flix6x wants to merge 2 commits into
Conversation
Introduce a PriceField subclass of VariableQuantityField marking monetary fields. The flex-context's shared-currency check now selects fields by isinstance instead of the *price name-suffix convention, and extends to the nested commitment prices (up-price/down-price), which were previously not held to the flex-context's shared currency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki
Documentation build overview
5 files changed ·
|
Member
Author
|
I self-approve this, but maybe you also want to have a look @nhoening. |
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.
Summary
Introduces a
PriceFieldmarker subclass ofVariableQuantityFieldfor monetary fields, and uses it in two ways:FlexContextSchema._try_to_convert_price_unitsnow selects fields byisinstance(field, PriceField)instead of thefield[-5:] == "price"name-suffix convention. Same ten fields as before — but future price fields get currency validation by declaration rather than by naming discipline.up-price/down-priceinCommitmentSchema) are now also declared asPriceFields and held to the flex-context'sshared_currency_unit, which they previously escaped. A commitment price in a different currency now fails at deserialization with the usual example-unit hint (and commitments can establish the shared currency when no top-level price field does).Since commitment prices may be per-energy or per-power, a small
_extract_currency_unithelper obtains the currency part of a price unit regardless of denominator.Relation to #2310
Split out from #2310, which builds on this to validate flex-model price fields (
soc-value-at-end) against the flex-context currency. This PR is pure refactoring plus the commitments currency check and can land independently.Tests
Three new
FlexContextSchemacases: commitment price in USD vs EUR context (rejected), matching EUR prices incl. kWh-denominated (accepted), and mixed currencies within one commitment with no top-level price (rejected).🤖 Generated with Claude Code
https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki