Checks

Validation helpers for checking classes, objects, collections, memberships, properties, attributes, scenarios, data records, and tags in a PlexosDB database.

Checks used on plexosdb.

plexosdb.checks.check_memberships_from_records(memberships)

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:

True when all records contain exactly the expected keys, otherwise False.

Return type:

bool

plexosdb.checks.check_attribute_exists(db, attribute_name, /, *, object_name, object_class)

Check if an attribute exists for a specific object.

Parameters:
  • db (PlexosDB) – Database instance.

  • attribute_name (str) – Name of the attribute to validate.

  • object_name (str) – Name of the target object.

  • object_class (ClassEnum) – Class for the target object.

Returns:

True if the object has an assigned value for the attribute.

Return type:

bool

plexosdb.checks.check_class_exists(db, class_enum)

Check if a class exists in the database.

Determines whether a class with the given enumeration exists in the schema.

Parameters:
  • db (PlexosDB) – Database instance.

  • class_enum (ClassEnum) – Class enumeration to check.

Returns:

True if the class exists, False otherwise.

Return type:

bool

See also

PlexosDB.get_class_id

Get the ID for a class.

PlexosDB.list_classes

List all available classes.

plexosdb.checks.check_category_exists(db, class_enum, name)

Check if a category exists for a specific class.

Determines whether a category with the given name exists for the specified class.

Parameters:
  • db (PlexosDB) – Database instance.

  • class_enum (ClassEnum) – Class enumeration to check the category for.

  • name (str) – Name of the category to check.

Returns:

True if the category exists, False otherwise.

Return type:

bool

Raises:

NotFoundError – If class_enum does not exist in the database. This indicates a programming error because categories are class-scoped.

plexosdb.checks.check_collection_exists(db, collection_enum, /, *, parent_class=None, child_class=None)

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 (PlexosDB) – Database instance.

  • collection_enum (CollectionEnum) – Collection enumeration to check.

  • parent_class (ClassEnum | None, optional) – Parent class enumeration to filter by.

  • child_class (ClassEnum | None, optional) – Child class enumeration to filter by.

Returns:

True if the collection exists (matching all specified criteria), False otherwise.

Return type:

bool

Raises:

NotFoundError – If 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.

plexosdb.checks.check_data_id_exist(db, data_id)

Check that a data id is present on t_data table.

Parameters:
  • db (PlexosDB) – Database instance.

  • data_id (int) – Data row identifier.

Returns:

True when data_id exists in t_data, False otherwise.

Return type:

bool

plexosdb.checks.check_tag_exists(db, data_id, object_id)

Check if a tag exists linking a data record to an object.

Parameters:
  • db (PlexosDB) – Database instance.

  • data_id (int) – Data ID to check.

  • object_id (int) – Object ID to check.

Returns:

True if a t_tag row exists for the pair (data_id, object_id), otherwise False.

Return type:

bool

plexosdb.checks.check_membership_exists(db, parent_object_name, child_object_name, /, *, parent_class, child_class, collection)

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 (PlexosDB) – Database instance.

  • parent_object_name (str) – Name of the parent object.

  • child_object_name (str) – Name of the child object.

  • parent_class (ClassEnum) – Class enumeration of the parent object.

  • child_class (ClassEnum) – Class enumeration of the child object.

  • collection (CollectionEnum) – Collection enumeration defining the relationship type.

Returns:

True if the membership exists, False otherwise.

Return type:

bool

Raises:

NotFoundError – If parent class, child class, or collection filter is invalid.

plexosdb.checks.check_object_exists(db, class_enum, /, name, *, category=None)

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 (PlexosDB) – Database instance.

  • class_enum (ClassEnum) – Class enumeration of the object.

  • name (str) – Name of the object to check.

  • category (str | None, optional) – Category name to filter by.

Returns:

True if the object exists (and matches category if specified), False otherwise.

Return type:

bool

Raises:

NotFoundError – If class_enum does not exist in the database.

plexosdb.checks.check_property_exists(db, collection_enum, /, object_class, property_names, *, parent_class=None)

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 (PlexosDB) – Database instance.

  • collection_enum (CollectionEnum) – Collection enumeration the properties should belong to.

  • object_class (ClassEnum) – Class enumeration of the object.

  • property_names (str | Iterable[str]) – Property name or names to check.

  • parent_class (ClassEnum | None, optional) – Class enumeration of the parent object.

Returns:

True if all properties exist, False otherwise.

Return type:

bool

Raises:

NotFoundError – If 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.

plexosdb.checks.check_scenario_exists(db, name)

Check if a scenario exists in the database.

Determines whether a scenario with the given name exists.

Parameters:
  • db (PlexosDB) – Database instance.

  • name (str) – Name of the scenario to check.

Returns:

True if the scenario exists, False otherwise.

Return type:

bool

See also

PlexosDB.get_class_id

Get the ID for a class.

ClassEnum.Scenario

Scenario class enumeration.

plexosdb.checks.register_plexosdb_check_methods(plexosdb_cls)

Attach check_* instance methods to PlexosDB from this module.

Parameters:

plexosdb_cls (type[PlexosDB])

Return type:

None

The 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.