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)
| 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`. |