Return exactly one instance based on the given primary key identifier, or raise an exception if not found. Raises :class:`_exc.NoResultFound` if the query selects no rows. For a detailed documentation of the arguments see the method :meth:`.Session.get`. ..
(
self,
entity: _EntityBindKey[_O],
ident: _PKIdentityArgument,
*,
options: Optional[Sequence[ORMOption]] = None,
populate_existing: bool | None = None,
with_for_update: ForUpdateParameter = None,
identity_token: Optional[Any] = None,
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
)
| 3830 | ) |
| 3831 | |
| 3832 | def get_one( |
| 3833 | self, |
| 3834 | entity: _EntityBindKey[_O], |
| 3835 | ident: _PKIdentityArgument, |
| 3836 | *, |
| 3837 | options: Optional[Sequence[ORMOption]] = None, |
| 3838 | populate_existing: bool | None = None, |
| 3839 | with_for_update: ForUpdateParameter = None, |
| 3840 | identity_token: Optional[Any] = None, |
| 3841 | execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, |
| 3842 | bind_arguments: Optional[_BindArguments] = None, |
| 3843 | ) -> _O: |
| 3844 | """Return exactly one instance based on the given primary key |
| 3845 | identifier, or raise an exception if not found. |
| 3846 | |
| 3847 | Raises :class:`_exc.NoResultFound` if the query selects no rows. |
| 3848 | |
| 3849 | For a detailed documentation of the arguments see the |
| 3850 | method :meth:`.Session.get`. |
| 3851 | |
| 3852 | .. versionadded:: 2.0.22 |
| 3853 | |
| 3854 | :return: The object instance. |
| 3855 | |
| 3856 | .. seealso:: |
| 3857 | |
| 3858 | :meth:`.Session.get` - equivalent method that instead |
| 3859 | returns ``None`` if no row was found with the provided primary |
| 3860 | key |
| 3861 | |
| 3862 | """ |
| 3863 | |
| 3864 | instance = self.get( |
| 3865 | entity, |
| 3866 | ident, |
| 3867 | options=options, |
| 3868 | populate_existing=populate_existing, |
| 3869 | with_for_update=with_for_update, |
| 3870 | identity_token=identity_token, |
| 3871 | execution_options=execution_options, |
| 3872 | bind_arguments=bind_arguments, |
| 3873 | ) |
| 3874 | |
| 3875 | if instance is None: |
| 3876 | raise sa_exc.NoResultFound( |
| 3877 | "No row was found when one was required" |
| 3878 | ) |
| 3879 | |
| 3880 | return instance |
| 3881 | |
| 3882 | def _get_impl( |
| 3883 | self, |