MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / _default_value

Method _default_value

lib/sqlalchemy/orm/attributes.py:1854–1869  ·  view source on GitHub ↗

Produce an empty collection for an un-initialized attribute

(
        self, state: InstanceState[Any], dict_: _InstanceDict
    )

Source from the content-addressed store, hash-verified

1852 del dict_[self.key]
1853
1854 def _default_value(
1855 self, state: InstanceState[Any], dict_: _InstanceDict
1856 ) -> _AdaptedCollectionProtocol:
1857 """Produce an empty collection for an un-initialized attribute"""
1858
1859 assert self.key not in dict_, (
1860 "_default_value should only be invoked for an "
1861 "uninitialized or expired attribute"
1862 )
1863
1864 if self.key in state._empty_collections:
1865 return state._empty_collections[self.key]
1866
1867 adapter, user_data = self._initialize_collection(state)
1868 adapter._set_empty(user_data)
1869 return user_data
1870
1871 def _initialize_collection(
1872 self, state: InstanceState[Any]

Callers 1

setMethod · 0.95

Calls 2

_set_emptyMethod · 0.80

Tested by

no test coverage detected