flexmeasures.data.schemas.utils
Functions
- flexmeasures.data.schemas.utils.convert_to_quantity(value: str, to_unit: str) Quantity
Convert value to quantity in the given unit.
- Parameters:
value – Value to convert.
to_unit – Unit to convert to. If the unit starts with a ‘/’, the value can have any unit, and the unit is used as the denominator.
- Returns:
Quantity in the desired unit.
- flexmeasures.data.schemas.utils.with_appcontext_if_needed()
Execute within the script’s application context, in case there is one.
An exception is any server
runcommand (e.g.flexmeasures runorflask run), which has a click context at the time the decorator is called, but no longer has a click context at the time the decorated function is called, which, typically, is a request to the running FlexMeasures server.The check walks up the entire context chain so it handles both: -
flask run: modules are imported while therunsubcommand context is current(
ctx.info_name == "run",ctx.invoked_subcommand is None).flexmeasures run: modules are imported at group level, where the parent context hasinvoked_subcommand == "run".
Classes
- class flexmeasures.data.schemas.utils.MarshmallowClickMixin(*args, **kwargs)
- __init__(*args, **kwargs)
- class flexmeasures.data.schemas.utils.SupportsLegacyFieldAliases
Mixin that lets a request schema accept legacy field names as aliases for their canonical replacements.
Subclasses set legacy_field_aliases, a dict mapping a legacy incoming key (as sent by an older client) to the schema’s current, canonical data_key. This lets us rename a public request field without breaking clients that still send the old name: both are accepted, and only the canonical field ends up being deserialized.
This is for request fields only. Response fields can’t “accept either” key on the way out, so backward compatibility there means including both keys in the response body instead (see e.g. job/schedule in the scheduling trigger response).
Exceptions
- exception flexmeasures.data.schemas.utils.FMValidationError(message: str | list | dict, field_name: str = '_schema', data: Mapping[str, Any] | Iterable[Mapping[str, Any]] | None = None, valid_data: list[Any] | dict[str, Any] | None = None, **kwargs)
Custom validation error class. It differs from the classic validation error by having two attributes, according to the USEF 2015 reference implementation. Subclasses of this error might adjust the status attribute accordingly.