MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _is_orphan

Method _is_orphan

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

Source from the content-addressed store, hash-verified

2498 )
2499
2500 def _is_orphan(self, state: InstanceState[_O]) -> bool:
2501 orphan_possible = False
2502 for mapper in self.iterate_to_root():
2503 for key, cls in mapper._delete_orphans:
2504 orphan_possible = True
2505
2506 has_parent = attributes.manager_of_class(cls).has_parent(
2507 state, key, optimistic=state.has_identity
2508 )
2509
2510 if self.legacy_is_orphan and has_parent:
2511 return False
2512 elif not self.legacy_is_orphan and not has_parent:
2513 return True
2514
2515 if self.legacy_is_orphan:
2516 return orphan_possible
2517 else:
2518 return False
2519
2520 def has_property(self, key: str) -> bool:
2521 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