MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / from_collection

Method from_collection

lib/sqlalchemy/orm/attributes.py:2486–2518  ·  view source on GitHub ↗
(
        cls,
        attribute: CollectionAttributeImpl,
        state: InstanceState[Any],
        current: Any,
    )

Source from the content-addressed store, hash-verified

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
2521HISTORY_BLANK = History((), (), ())

Callers 1

get_historyMethod · 0.80

Calls 2

instance_stateFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected