MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _is_orphan

Method _is_orphan

lib/sqlalchemy/orm/mapper.py:2425–2443  ·  view source on GitHub ↗
(self, state: InstanceState[_O])

Source from the content-addressed store, hash-verified

2423 )
2424
2425 def _is_orphan(self, state: InstanceState[_O]) -> bool:
2426 orphan_possible = False
2427 for mapper in self.iterate_to_root():
2428 for key, cls in mapper._delete_orphans:
2429 orphan_possible = True
2430
2431 has_parent = attributes.manager_of_class(cls).has_parent(
2432 state, key, optimistic=state.has_identity
2433 )
2434
2435 if self.legacy_is_orphan and has_parent:
2436 return False
2437 elif not self.legacy_is_orphan and not has_parent:
2438 return True
2439
2440 if self.legacy_is_orphan:
2441 return orphan_possible
2442 else:
2443 return False
2444
2445 def has_property(self, key: str) -> bool:
2446 return key in self._props

Callers 9

_flushMethod · 0.80
removeFunction · 0.80
set_Function · 0.80
test_basicMethod · 0.80
_assert_not_orphanMethod · 0.80
_assert_is_orphanMethod · 0.80
test_no_orphanMethod · 0.80
test_no_orphanMethod · 0.80

Calls 3

iterate_to_rootMethod · 0.95
has_parentMethod · 0.80
manager_of_classMethod · 0.80

Tested by 6

test_basicMethod · 0.64
_assert_not_orphanMethod · 0.64
_assert_is_orphanMethod · 0.64
test_no_orphanMethod · 0.64
test_no_orphanMethod · 0.64