"""Non-doable elements of ProcessStep/Todo chains."""
from __future__ import annotations
-from typing import Any
-from sqlite3 import Row
from plomtask.db import DatabaseConnection, BaseModel
from plomtask.versioned_attributes import VersionedAttribute
from plomtask.exceptions import HandledException
self.description = VersionedAttribute(self, 'condition_descriptions',
'')
- @classmethod
- def from_table_row(cls, db_conn: DatabaseConnection,
- row: Row | list[Any]) -> Condition:
- """Build condition from row, including VersionedAttributes."""
- condition = super().from_table_row(db_conn, row)
- for name in ('title', 'description'):
- table_name = f'condition_{name}s'
- for row_ in db_conn.row_where(table_name, 'parent', row[0]):
- getattr(condition, name).history_from_row(row_)
- return condition
-
def remove(self, db_conn: DatabaseConnection) -> None:
"""Remove from DB, with VersionedAttributes.
# pylint: disable=unused-argument
db_conn: DatabaseConnection,
row: Row | list[Any]) -> BaseModelInstance:
- """Make from DB row, update DB cache with it."""
+ """Make from DB row (sans relations), update DB cache with it."""
obj = cls(*row)
+ assert obj.id_ is not None
+ for attr_name in cls.to_save_versioned:
+ attr = getattr(obj, attr_name)
+ table_name = attr.table_name
+ for row_ in db_conn.row_where(table_name, 'parent', obj.id_):
+ attr.history_from_row(row_)
obj._cache()
return obj
row: Row | list[Any]) -> Process:
"""Make from DB row, with dependencies."""
process = super().from_table_row(db_conn, row)
- assert isinstance(process.id_, int)
- for name in ('title', 'description', 'effort'):
- table = f'process_{name}s'
- for row_ in db_conn.row_where(table, 'parent', process.id_):
- getattr(process, name).history_from_row(row_)
+ assert process.id_ is not None
for name in ('conditions', 'blockers', 'enables', 'disables'):
table = f'process_{name}'
assert isinstance(process.id_, int)