12 lines
381 B
Python
12 lines
381 B
Python
import json
|
|
|
|
def capture_diff(obj, new_state):
|
|
"""Return a dict mapping field -> (old, new) for changed fields."""
|
|
old_state = {k: getattr(obj, k) for k in obj.__dict__ if not k.startswith('_')}
|
|
diff = {}
|
|
for k, new_val in new_state.items():
|
|
old_val = old_state.get(k)
|
|
if old_val != new_val:
|
|
diff[k] = (old_val, new_val)
|
|
return diff
|