fix: inherit @watch field filter from parent classes via MRO traversal (#170)

This commit is contained in:
d3vyce
2026-03-23 19:08:17 +01:00
committed by GitHub
parent 0c7a99039c
commit 6981c33dc8
3 changed files with 137 additions and 1 deletions

View File

@@ -66,6 +66,14 @@ def _snapshot_column_attrs(obj: Any) -> dict[str, Any]:
}
def _get_watched_fields(cls: type) -> list[str] | None:
"""Return the watched fields for *cls*, walking the MRO to inherit from parents."""
for klass in cls.__mro__:
if klass in _WATCHED_FIELDS:
return _WATCHED_FIELDS[klass]
return None
def _upsert_changes(
pending: dict[int, tuple[Any, dict[str, dict[str, Any]]]],
obj: Any,
@@ -103,7 +111,7 @@ def _after_flush(session: Any, flush_context: Any) -> None:
continue
# None = not in dict = watch all fields; list = specific fields only
watched = _WATCHED_FIELDS.get(type(obj))
watched = _get_watched_fields(type(obj))
changes: dict[str, dict[str, Any]] = {}
attrs = (