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)
| 3556 | persistent_to_deleted(self, state) |
| 3557 | |
| 3558 | def add(self, instance: object, *, _warn: bool = True) -> None: |
| 3559 | class="st">"""Place an object into this :class:`_orm.Session`. |
| 3560 | |
| 3561 | Objects that are in the :term:`transient` state when passed to the |
| 3562 | :meth:`_orm.Session.add` method will move to the |
| 3563 | :term:`pending` state, until the next flush, at which point they |
| 3564 | will move to the :term:`persistent` state. |
| 3565 | |
| 3566 | Objects that are in the :term:`detached` state when passed to the |
| 3567 | :meth:`_orm.Session.add` method will move to the :term:`persistent` |
| 3568 | state directly. |
| 3569 | |
| 3570 | If the transaction used by the :class:`_orm.Session` is rolled back, |
| 3571 | objects which were transient when they were passed to |
| 3572 | :meth:`_orm.Session.add` will be moved back to the |
| 3573 | :term:`transient` state, and will no longer be present within this |
| 3574 | :class:`_orm.Session`. |
| 3575 | |
| 3576 | .. seealso:: |
| 3577 | |
| 3578 | :meth:`_orm.Session.add_all` |
| 3579 | |
| 3580 | :ref:`session_adding` - at :ref:`session_basics` |
| 3581 | |
| 3582 | class="st">""" |
| 3583 | if _warn and self._warn_on_events: |
| 3584 | self._flush_warning(class="st">"Session.add()") |
| 3585 | |
| 3586 | try: |
| 3587 | state = attributes.instance_state(instance) |
| 3588 | except exc.NO_STATE as err: |
| 3589 | raise exc.UnmappedInstanceError(instance) from err |
| 3590 | |
| 3591 | self._save_or_update_state(state) |
| 3592 | |
| 3593 | def add_all(self, instances: Iterable[object]) -> None: |
| 3594 | class="st">"""Add the given collection of instances to this :class:`_orm.Session`. |