]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- illustrate these using the newer exception doctest format.
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 14 Jan 2016 23:20:00 +0000 (18:20 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 14 Jan 2016 23:20:34 +0000 (18:20 -0500)
unfortunately we can't show the SQL unless we filtered it out
from doctest...not worth it

(cherry picked from commit 7bb578b1bd61ec9a2506d1bdb60bb28579204808)

doc/build/orm/tutorial.rst

index 6bb69171922aa1521a8e822ffce7664eec0e2a59..9e0d262cd831f870394e3456f42167dff997fbd6 100644 (file)
@@ -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