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
13 changes: 10 additions & 3 deletions src/plexosdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,9 @@ def iterate_properties(
if property_names:
check_collection = collection or (get_default_collection(class_enum) if class_enum else None)
props = (
self._validate_properties(property_names, check_collection, class_enum)
self._validate_properties(
property_names, check_collection, class_enum, parent_class=parent_class
)
if check_collection and class_enum
else normalize_names(property_names)
)
Expand Down Expand Up @@ -4348,11 +4350,16 @@ def _validate_and_filter_objects(
return valid_names

def _validate_properties(
self, property_names: str | Iterable[str], collection: CollectionEnum, class_enum: ClassEnum
self,
property_names: str | Iterable[str],
collection: CollectionEnum,
class_enum: ClassEnum,
*,
parent_class: ClassEnum | None = None,
) -> list[str]:
"""Validate properties exist for collection and return normalized list."""
props = normalize_names(property_names)
if not self.check_property_exists(collection, class_enum, props):
if not self.check_property_exists(collection, class_enum, props, parent_class=parent_class):
msg = (
f"Invalid property {props} for collection={collection}. "
"Use `list_valid_properties()` to check valid properties."
Expand Down
42 changes: 42 additions & 0 deletions tests/test_plexosdb_iterate_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,45 @@ def test_iterate_properties_yields_property_records(db_thermal_gen: PlexosDB) ->
assert len(results) > 0
for record in results:
assert isinstance(record, dict)


def test_iterate_properties_with_non_system_parent_class(
db_with_reserve_collection_property: PlexosDB,
) -> None:
"""Test that parent_class context is propagated for property validation."""
from plexosdb import ClassEnum, CollectionEnum

db = db_with_reserve_collection_property

results = list(
db.iterate_properties(
class_enum=ClassEnum.Region,
object_names="region-01",
property_names=["Load Risk"],
parent_class=ClassEnum.Reserve,
collection=CollectionEnum.Regions,
)
)

assert len(results) == 1
assert results[0]["property"] == "Load Risk"


def test_get_object_properties_with_non_system_parent_class(
db_with_reserve_collection_property: PlexosDB,
) -> None:
"""Test that get_object_properties respects parent_class_enum for validation."""
from plexosdb import ClassEnum, CollectionEnum

db = db_with_reserve_collection_property

props = db.get_object_properties(
ClassEnum.Region,
"region-01",
property_names=["Load Risk"],
parent_class_enum=ClassEnum.Reserve,
collection_enum=CollectionEnum.Regions,
)

assert len(props) == 1
assert props[0]["property"] == "Load Risk"