MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / hasparent

Method hasparent

lib/sqlalchemy/orm/attributes.py:962–985  ·  view source on GitHub ↗

Return the boolean value of a `hasparent` flag attached to the given state. The `optimistic` flag determines what the default return value should be if no `hasparent` flag can be located. As this function is used to determine if an instance is an *orphan*, i

(
        self, state: InstanceState[Any], optimistic: bool = False
    )

Source from the content-addressed store, hash-verified

960 active_history = property(_get_active_history, _set_active_history)
961
962 def hasparent(
963 self, state: InstanceState[Any], optimistic: bool = False
964 ) -> bool:
965 """Return the boolean value of a `hasparent` flag attached to
966 the given state.
967
968 The `optimistic` flag determines what the default return value
969 should be if no `hasparent` flag can be located.
970
971 As this function is used to determine if an instance is an
972 *orphan*, instances that were loaded from storage should be
973 assumed to not be orphans, until a True/False value for this
974 flag is set.
975
976 An instance attribute that is loaded by a callable function
977 will also not have a `hasparent` flag.
978
979 """
980 msg = "This AttributeImpl is not configured to track parents."
981 assert self.trackparent, msg
982
983 return (
984 state.parents.get(id(self.parent_token), optimistic) is not False
985 )
986
987 def sethasparent(
988 self,

Callers 6

has_parentMethod · 0.45
hasparentMethod · 0.45
hasparentMethod · 0.45
_do_checkFunction · 0.45
test_no_orphanMethod · 0.45
test_no_orphanMethod · 0.45

Calls 1

getMethod · 0.45

Tested by 2

test_no_orphanMethod · 0.36
test_no_orphanMethod · 0.36