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

Method delete

lib/sqlalchemy/orm/session.py:3521–3550  ·  view source on GitHub ↗

Mark an instance as deleted. The object is assumed to be either :term:`persistent` or :term:`detached` when passed; after the method is called, the object will remain in the :term:`persistent` state until the next flush proceeds. During this time, the object will al

(self, instance: object)

Source from the content-addressed store, hash-verified

3519 self._save_or_update_impl(st_)
3520
3521 def delete(self, instance: object) -> None:
3522 """Mark an instance as deleted.
3523
3524 The object is assumed to be either :term:`persistent` or
3525 :term:`detached` when passed; after the method is called, the
3526 object will remain in the :term:`persistent` state until the next
3527 flush proceeds. During this time, the object will also be a member
3528 of the :attr:`_orm.Session.deleted` collection.
3529
3530 When the next flush proceeds, the object will move to the
3531 :term:`deleted` state, indicating a ``DELETE`` statement was emitted
3532 for its row within the current transaction. When the transaction
3533 is successfully committed,
3534 the deleted object is moved to the :term:`detached` state and is
3535 no longer present within this :class:`_orm.Session`.
3536
3537 .. seealso::
3538
3539 :ref:`session_deleting` - at :ref:`session_basics`
3540
3541 """
3542 if self._warn_on_events:
3543 self._flush_warning("Session.delete()")
3544
3545 try:
3546 state = attributes.instance_state(instance)
3547 except exc.NO_STATE as err:
3548 raise exc.UnmappedInstanceError(instance) from err
3549
3550 self._delete_impl(state, instance, head=True)
3551
3552 def _delete_impl(
3553 self, state: InstanceState[Any], obj: object, head: bool

Callers 5

test_ensure_cacheMethod · 0.95
test_delete_bothMethod · 0.95
test_persistMethod · 0.95
goMethod · 0.95

Calls 2

_flush_warningMethod · 0.95
_delete_implMethod · 0.95

Tested by 5

test_ensure_cacheMethod · 0.76
test_delete_bothMethod · 0.76
test_persistMethod · 0.76
goMethod · 0.76