Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

## Bug Fixes

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
- Fixed auto-formula population to only fill formulas for component types already present in a microgrid configuration. This prevents creating placeholder entries with `None` formulas for component types that are not configured.
15 changes: 12 additions & 3 deletions src/frequenz/gridpool/_microgrid_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,13 @@ async def load_configs_with_formulas(
assets_url, auth_key=assets_auth_key, sign_secret=assets_sign_secret
) as assets_client:
for microgrid_id, config in microgrid_configs.items():
relevant_ctypes = set(config.ctype.keys())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this only load configs for ctypes that are loaded from the file? In future we don't want to pass in config files if not necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this logic assumes that we have a config file. load_configs also assumes we have a config file in place.
I will test out changes needed for these functions to work without a config file in a separate PR.


await populate_missing_formulas(
microgrid_id=int(microgrid_id),
config=config,
assets_client=assets_client,
component_types=relevant_ctypes,
)

return microgrid_configs
Expand All @@ -454,6 +457,7 @@ async def populate_missing_formulas(
microgrid_id: int,
config: "MicrogridConfig",
assets_client: AssetsApiClient,
component_types: set[str] | None = None,
) -> None:
"""Populate missing component formulas from the assets API graph.

Expand All @@ -471,6 +475,8 @@ async def populate_missing_formulas(
Microgrid configuration object to update in place.
assets_client:
Assets API client used to fetch the component graph.
component_types:
Optional set of component types to consider when populating formulas.

Returns:
None. The configuration is modified in place.
Expand Down Expand Up @@ -502,12 +508,15 @@ async def populate_missing_formulas(
"AC_ENERGY_ACTIVE_DELIVERED",
)

# Default: only populate component types already present in the config.
allowed_ctypes = component_types or set(config.ctype.keys())

for ctype, formula in auto_formulas.items():
if ctype not in allowed_ctypes:
continue

cfg = config.ctype.get(ctype)
if cfg is None:
config.ctype[ctype] = ComponentTypeConfig(
formula={metric: formula for metric in metrics}
)
continue

if cfg.formula is None:
Expand Down
Loading