]> 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:00 +0000 (18:20 -0500)
unfortunately we can't show the SQL unless we filtered it out
from doctest...not worth it

doc/build/orm/tutorial.rst

index 6e98dfc9cc0cb613847b3e0f0dbc82c120f78be9..4349f75f2bb2e770b4836e4a6c672b25a4d7e052 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