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

Method add

lib/sqlalchemy/orm/session.py:3456–3489  ·  view source on GitHub ↗

Place an object into this :class:`_orm.Session`. Objects that are in the :term:`transient` state when passed to the :meth:`_orm.Session.add` method will move to the :term:`pending` state, until the next flush, at which point they will move to the :term:`persistent` s

(self, instance: object, _warn: bool = True)

Source from the content-addressed store, hash-verified

3454 persistent_to_deleted(self, state)
3455
3456 def add(self, instance: object, _warn: bool = True) -> None:
3457 """Place an object into this :class:`_orm.Session`.
3458
3459 Objects that are in the :term:`transient` state when passed to the
3460 :meth:`_orm.Session.add` method will move to the
3461 :term:`pending` state, until the next flush, at which point they
3462 will move to the :term:`persistent` state.
3463
3464 Objects that are in the :term:`detached` state when passed to the
3465 :meth:`_orm.Session.add` method will move to the :term:`persistent`
3466 state directly.
3467
3468 If the transaction used by the :class:`_orm.Session` is rolled back,
3469 objects which were transient when they were passed to
3470 :meth:`_orm.Session.add` will be moved back to the
3471 :term:`transient` state, and will no longer be present within this
3472 :class:`_orm.Session`.
3473
3474 .. seealso::
3475
3476 :meth:`_orm.Session.add_all`
3477
3478 :ref:`session_adding` - at :ref:`session_basics`
3479
3480 """
3481 if _warn and self._warn_on_events:
3482 self._flush_warning("Session.add()")
3483
3484 try:
3485 state = attributes.instance_state(instance)
3486 except exc.NO_STATE as err:
3487 raise exc.UnmappedInstanceError(instance) from err
3488
3489 self._save_or_update_state(state)
3490
3491 def add_all(self, instances: Iterable[object]) -> None:
3492 """Add the given collection of instances to this :class:`_orm.Session`.

Callers 15

add_allMethod · 0.95
test_mutableMethod · 0.95
test_modifiedMethod · 0.95
test_mutableMethod · 0.95
test_modifiedMethod · 0.95
test_cast_typeMethod · 0.95
test_multi_dimensionMethod · 0.95
_test_premature_flushMethod · 0.95
insert_dataMethod · 0.95
insert_dataMethod · 0.95
insert_dataMethod · 0.95
insert_dataMethod · 0.95

Calls 2

_flush_warningMethod · 0.95
_save_or_update_stateMethod · 0.95

Tested by 15

test_mutableMethod · 0.76
test_modifiedMethod · 0.76
test_mutableMethod · 0.76
test_modifiedMethod · 0.76
test_cast_typeMethod · 0.76
test_multi_dimensionMethod · 0.76
_test_premature_flushMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76