From: Mike Bayer Date: Thu, 14 Jan 2016 23:20:00 +0000 (-0500) Subject: - illustrate these using the newer exception doctest format. X-Git-Tag: rel_1_1_0b1~84^2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bb578b1bd61ec9a2506d1bdb60bb28579204808;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - illustrate these using the newer exception doctest format. unfortunately we can't show the SQL unless we filtered it out from doctest...not worth it --- diff --git a/doc/build/orm/tutorial.rst b/doc/build/orm/tutorial.rst index 6e98dfc9cc..4349f75f2b 100644 --- a/doc/build/orm/tutorial.rst +++ b/doc/build/orm/tutorial.rst @@ -861,37 +861,19 @@ database results. Here's a brief tour: .. sourcecode:: python+sql - {sql}>>> from sqlalchemy.orm.exc import MultipleResultsFound - >>> try: - ... user = query.one() - ... except MultipleResultsFound as e: - ... print(e) - SELECT users.id AS users_id, - users.name AS users_name, - users.fullname AS users_fullname, - users.password AS users_password - FROM users - WHERE users.name LIKE ? ORDER BY users.id - ('%ed',) - {stop}Multiple rows were found for one() + >>> user = query.one() + Traceback (most recent call last): + ... + MultipleResultsFound: Multiple rows were found for one() With no rows found: .. sourcecode:: python+sql - {sql}>>> from sqlalchemy.orm.exc import NoResultFound - >>> try: - ... user = query.filter(User.id == 99).one() - ... except NoResultFound as e: - ... print(e) - SELECT users.id AS users_id, - users.name AS users_name, - users.fullname AS users_fullname, - users.password AS users_password - FROM users - WHERE users.name LIKE ? AND users.id = ? ORDER BY users.id - ('%ed', 99) - {stop}No row was found for one() + >>> user = query.filter(User.id == 99).one() + Traceback (most recent call last): + ... + NoResultFound: No row was found for one() The :meth:`~.Query.one` method is great for systems that expect to handle "no items found" versus "multiple items found" differently; such as a RESTful