(
cls,
attribute: CollectionAttributeImpl,
state: InstanceState[Any],
current: Any,
)
| 2484 | |
| 2485 | @classmethod |
| 2486 | def from_collection( |
| 2487 | cls, |
| 2488 | attribute: CollectionAttributeImpl, |
| 2489 | state: InstanceState[Any], |
| 2490 | current: Any, |
| 2491 | ) -> History: |
| 2492 | original = state.committed_state.get(attribute.key, _NO_HISTORY) |
| 2493 | if current is NO_VALUE: |
| 2494 | return cls((), (), ()) |
| 2495 | |
| 2496 | current = getattr(current, "_sa_adapter") |
| 2497 | if original is NO_VALUE: |
| 2498 | return cls(list(current), (), ()) |
| 2499 | elif original is _NO_HISTORY: |
| 2500 | return cls((), list(current), ()) |
| 2501 | else: |
| 2502 | current_states = [ |
| 2503 | ((c is not None) and instance_state(c) or None, c) |
| 2504 | for c in current |
| 2505 | ] |
| 2506 | original_states = [ |
| 2507 | ((c is not None) and instance_state(c) or None, c) |
| 2508 | for c in original |
| 2509 | ] |
| 2510 | |
| 2511 | current_set = dict(current_states) |
| 2512 | original_set = dict(original_states) |
| 2513 | |
| 2514 | return cls( |
| 2515 | [o for s, o in current_states if s not in original_set], |
| 2516 | [o for s, o in current_states if s in original_set], |
| 2517 | [o for s, o in original_states if s not in current_set], |
| 2518 | ) |
| 2519 | |
| 2520 | |
| 2521 | HISTORY_BLANK = History((), (), ()) |
no test coverage detected