MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _detach_states

Method _detach_states

lib/sqlalchemy/orm/state.py:468–503  ·  view source on GitHub ↗
(
        self,
        states: Iterable[InstanceState[_O]],
        session: Session,
        to_transient: bool = False,
    )

Source from the content-addressed store, hash-verified

466
467 @classmethod
468 def _detach_states(
469 self,
470 states: Iterable[InstanceState[_O]],
471 session: Session,
472 to_transient: bool = False,
473 ) -> None:
474 persistent_to_detached = (
475 session.dispatch.persistent_to_detached or None
476 )
477 deleted_to_detached = session.dispatch.deleted_to_detached or None
478 pending_to_transient = session.dispatch.pending_to_transient or None
479 persistent_to_transient = (
480 session.dispatch.persistent_to_transient or None
481 )
482
483 for state in states:
484 deleted = state._deleted
485 pending = state.key is None
486 persistent = not pending and not deleted
487
488 state.session_id = None
489
490 if to_transient and state.key:
491 del state.key
492 if persistent:
493 if to_transient:
494 if persistent_to_transient is not None:
495 persistent_to_transient(session, state)
496 elif persistent_to_detached is not None:
497 persistent_to_detached(session, state)
498 elif deleted and deleted_to_detached is not None:
499 deleted_to_detached(session, state)
500 elif pending and pending_to_transient is not None:
501 pending_to_transient(session, state)
502
503 state._strong_obj = None
504
505 def _detach(self, session: Optional[Session] = None) -> None:
506 if session:

Callers 4

_detachMethod · 0.80
_remove_snapshotMethod · 0.80
expunge_allMethod · 0.80
_expunge_statesMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected