Checks
Validation helpers for checking classes, objects, collections, memberships,
properties, attributes, scenarios, data records, and tags in a PlexosDB
database.
For whole-database validation and text reports, see
Validating a Database. Use the public
PlexosDB.validate_database() entry point; _find_* functions are internal
helpers that consume a SQLiteManager.
The existence-check helpers accept a PlexosDB instance as their first
argument. The same checks are also available as convenience methods on
PlexosDB where the class exposes them.
Public module members
Section titled “Public module members”plexosdb.checks
Section titled “plexosdb.checks”check_memberships_from_records
Section titled “check_memberships_from_records”Validate membership records have the exact required fields.
Parameters
memberships : list[dict[str, int]]Membership dictionaries expected to contain exactly these keys: parent_object_id, child_object_id, collection_id, child_class_id, parent_class_id.
Returns
boolTrue when all records contain exactly the expected keys, otherwise False.
check_memberships_from_records(memberships: list[dict[str, int]]) -> boolcheck_attribute_exists
Section titled “check_attribute_exists”Check if an attribute exists for a specific object.
Parameters
db : PlexosDBDatabase instance.attribute_name : strName of the attribute to validate.object_name : strName of the target object.object_class : ClassEnumClass for the target object.
Returns
boolTrue if the object has an assigned value for the attribute.
check_attribute_exists(db: PlexosDB, attribute_name: str, /, *, object_name: str, object_class: ClassEnum) -> boolcheck_class_exists
Section titled “check_class_exists”Check if a class exists in the database.
Determines whether a class with the given enumeration exists in the schema.
Parameters
db : PlexosDBDatabase instance.class_enum : ClassEnumClass enumeration to check.
Returns
boolTrue if the class exists, False otherwise.
See Also
PlexosDB.get_class_id: Get the ID for a class.PlexosDB.list_classes: List all available classes.
check_class_exists(db: PlexosDB, class_enum: ClassEnum) -> boolcheck_category_exists
Section titled “check_category_exists”Check if a category exists for a specific class.
Determines whether a category with the given name exists for the specified class.
Parameters
db : PlexosDBDatabase instance.class_enum : ClassEnumClass enumeration to check the category for.name : strName of the category to check.
Returns
boolTrue if the category exists, False otherwise.
Raises
NotFoundErrorIf class_enum does not exist in the database. This indicates a programming error because categories are class-scoped.
check_category_exists(db: PlexosDB, class_enum: ClassEnum, name: str) -> boolcheck_collection_exists
Section titled “check_collection_exists”Check if a collection exists in the database.
Determines whether a collection with the given enumeration exists, optionally filtered by parent and/or child class.
Parameters
db : PlexosDBDatabase instance.collection_enum : CollectionEnumCollection enumeration to check.parent_class : ClassEnum | None, optionalParent class enumeration to filter by.child_class : ClassEnum | None, optionalChild class enumeration to filter by.
Returns
boolTrue if the collection exists (matching all specified criteria), False otherwise.
Raises
NotFoundErrorIf parent_class or child_class is specified but does not exist.
Notes
The method returns False only when the collection itself does not exist or does not match the requested class filter.
check_collection_exists(db: PlexosDB, collection_enum: CollectionEnum, /, *, parent_class: ClassEnum | None=None, child_class: ClassEnum | None=None) -> boolcheck_data_id_exist
Section titled “check_data_id_exist”Check that a data id is present on t_data table.
Parameters
db : PlexosDBDatabase instance.data_id : intData row identifier.
Returns
boolTrue when data_id exists in t_data, False otherwise.
check_data_id_exist(db: PlexosDB, data_id: int) -> boolcheck_tag_exists
Section titled “check_tag_exists”Check if a tag exists linking a data record to an object.
Parameters
db : PlexosDBDatabase instance.data_id : intData ID to check.object_id : intObject ID to check.
Returns
boolTrue if a t_tag row exists for the pair (data_id, object_id), otherwise False.
check_tag_exists(db: PlexosDB, data_id: int, object_id: int) -> boolcheck_membership_exists
Section titled “check_membership_exists”Check if a membership exists between two objects.
Determines whether a membership relationship exists between the specified parent and child objects within the given collection.
Parameters
db : PlexosDBDatabase instance.parent_object_name : strName of the parent object.child_object_name : strName of the child object.parent_class : ClassEnumClass enumeration of the parent object.child_class : ClassEnumClass enumeration of the child object.collection : CollectionEnumCollection enumeration defining the relationship type.
Returns
boolTrue if the membership exists, False otherwise.
Raises
NotFoundErrorIf parent class, child class, or collection filter is invalid.
check_membership_exists(db: PlexosDB, parent_object_name: str, child_object_name: str, /, *, parent_class: ClassEnum, child_class: ClassEnum, collection: CollectionEnum) -> boolcheck_object_exists
Section titled “check_object_exists”Check if an object exists in the database.
Determines whether an object with the given name and class exists, optionally filtered by category.
Parameters
db : PlexosDBDatabase instance.class_enum : ClassEnumClass enumeration of the object.name : strName of the object to check.category : str | None, optionalCategory name to filter by.
Returns
boolTrue if the object exists (and matches category if specified), False otherwise.
Raises
NotFoundErrorIf class_enum does not exist in the database.
check_object_exists(db: PlexosDB, class_enum: ClassEnum, /, name: str, *, category: str | None=None) -> boolcheck_property_exists
Section titled “check_property_exists”Check if properties exist for a specific collection and class.
Verifies that all specified property names are valid for the given collection and class.
Parameters
db : PlexosDBDatabase instance.collection_enum : CollectionEnumCollection enumeration the properties should belong to.object_class : ClassEnumClass enumeration of the object.property_names : str | Iterable[str]Property name or names to check.parent_class : ClassEnum | None, optionalClass enumeration of the parent object.
Returns
boolTrue if all properties exist, False otherwise.
Raises
NotFoundErrorIf parent class, child class, or collection filter is invalid.
Notes
If any property in the list is invalid, the function returns False and logs the invalid list.
check_property_exists(db: PlexosDB, collection_enum: CollectionEnum, /, object_class: ClassEnum, property_names: str | Iterable[str], *, parent_class: ClassEnum | None=None) -> boolcheck_scenario_exists
Section titled “check_scenario_exists”Check if a scenario exists in the database.
Determines whether a scenario with the given name exists.
Parameters
db : PlexosDBDatabase instance.name : strName of the scenario to check.
Returns
boolTrue if the scenario exists, False otherwise.
See Also
PlexosDB.get_class_id: Get the ID for a class.ClassEnum.Scenario: Scenario class enumeration.
check_scenario_exists(db: PlexosDB, name: str) -> boolget_default_schema_columns
Section titled “get_default_schema_columns”Return table columns introspected from the packaged PLEXOS schema.
get_default_schema_columns() -> tuple[tuple[str, frozenset[str]], ...]validate_value_by_rule
Section titled “validate_value_by_rule”Validate a numeric value using Between, In, or comparison rules.
validate_value_by_rule(value: SQLiteValue, validation_rule: str) -> ValidationResultrepair_safe_membership_class_ids
Section titled “repair_safe_membership_class_ids”Repair membership class IDs when the object and collection agree.
repair_safe_membership_class_ids(db: SQLiteManager, /) -> Noneregister_plexosdb_check_methods
Section titled “register_plexosdb_check_methods”Attach check_* instance methods to PlexosDB from this module.
register_plexosdb_check_methods(plexosdb_cls: type[PlexosDB]) -> None