MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / init_state_collection

Function init_state_collection

lib/sqlalchemy/orm/attributes.py:2720–2744  ·  view source on GitHub ↗

Initialize a collection attribute and return the collection adapter. Discards any existing collection which may be there.

(
    state: InstanceState[Any], dict_: _InstanceDict, key: str
)

Source from the content-addressed store, hash-verified

2718
2719
2720def init_state_collection(
2721 state: InstanceState[Any], dict_: _InstanceDict, key: str
2722) -> CollectionAdapter:
2723 """Initialize a collection attribute and return the collection adapter.
2724
2725 Discards any existing collection which may be there.
2726
2727 """
2728 attr = state.manager[key].impl
2729
2730 if TYPE_CHECKING:
2731 assert isinstance(attr, _HasCollectionAdapter)
2732
2733 old = dict_.pop(key, None) # discard old collection
2734 if old is not None:
2735 old_collection = old._sa_adapter
2736 attr._dispose_previous_collection(state, old, old_collection, False)
2737
2738 user_data = attr._default_value(state, dict_)
2739 adapter: CollectionAdapter = attr.get_collection(
2740 state, dict_, user_data, passive=PassiveFlag.PASSIVE_NO_FETCH
2741 )
2742 adapter._reset_empty()
2743
2744 return adapter
2745
2746
2747def set_committed_value(instance: object, key: str, value: Any) -> None:

Callers 1

init_collectionFunction · 0.85

Calls 5

popMethod · 0.45
_default_valueMethod · 0.45
get_collectionMethod · 0.45
_reset_emptyMethod · 0.45

Tested by

no test coverage detected