MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _load_for_state

Method _load_for_state

lib/sqlalchemy/orm/strategies.py:888–1005  ·  view source on GitHub ↗
(
        self,
        state,
        passive,
        loadopt=None,
        extra_criteria=(),
        extra_options=(),
        alternate_effective_path=None,
        execution_options=util.EMPTY_DICT,
    )

Source from the content-addressed store, hash-verified

886 )
887
888 def _load_for_state(
889 self,
890 state,
891 passive,
892 loadopt=None,
893 extra_criteria=(),
894 extra_options=(),
895 alternate_effective_path=None,
896 execution_options=util.EMPTY_DICT,
897 ):
898 if not state.key and (
899 (
900 not self.parent_property.load_on_pending
901 and not state._load_pending
902 )
903 or not state.session_id
904 ):
905 return LoaderCallableStatus.ATTR_EMPTY
906
907 pending = not state.key
908 primary_key_identity = None
909
910 use_get = self.use_get and (not loadopt or not loadopt._extra_criteria)
911
912 if (not passive & PassiveFlag.SQL_OK and not use_get) or (
913 not passive & attributes.NON_PERSISTENT_OK and pending
914 ):
915 return LoaderCallableStatus.PASSIVE_NO_RESULT
916
917 if (
918 # we were given lazy="raise"
919 self._raise_always
920 # the no_raise history-related flag was not passed
921 and not passive & PassiveFlag.NO_RAISE
922 and (
923 # if we are use_get and related_object_ok is disabled,
924 # which means we are at most looking in the identity map
925 # for history purposes or otherwise returning
926 # PASSIVE_NO_RESULT, don't raise. This is also a
927 # history-related flag
928 not use_get
929 or passive & PassiveFlag.RELATED_OBJECT_OK
930 )
931 ):
932 self._invoke_raise_load(state, passive, "raise")
933
934 session = _state_session(state)
935 if not session:
936 if passive & PassiveFlag.NO_RAISE:
937 return LoaderCallableStatus.PASSIVE_NO_RESULT
938
939 raise orm_exc.DetachedInstanceError(
940 "Parent instance %s is not bound to a Session; "
941 "lazy load operation of attribute '%s' cannot proceed"
942 % (orm_util.state_str(state), self.key)
943 )
944
945 # if we have a simple primary key load, check the

Callers 3

__call__Method · 0.45
__call__Method · 0.45
_load_for_pathMethod · 0.45

Calls 7

_invoke_raise_loadMethod · 0.95
_emit_lazyloadMethod · 0.95
_state_sessionFunction · 0.85
intersectionMethod · 0.45
issupersetMethod · 0.45
_identity_lookupMethod · 0.45

Tested by

no test coverage detected