]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix type removing Optional for get_one and update if statement
authorCarlos Sousa <edu-eduardo99@hotmail.com>
Mon, 25 Sep 2023 15:15:35 +0000 (12:15 -0300)
committerCarlos Sousa <edu-eduardo99@hotmail.com>
Mon, 25 Sep 2023 15:15:35 +0000 (12:15 -0300)
lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/orm/session.py

index f8c5a287d546b7e0033eafa9b554f22e9dba4ced..14e5a484e686e288de0a6ffb4ea7fada47af5482 100644 (file)
@@ -623,7 +623,7 @@ class AsyncSession(ReversibleProxy[Session]):
         with_for_update: ForUpdateParameter = None,
         identity_token: Optional[Any] = None,
         execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
-    ) -> Optional[_O]:
+    ) -> _O:
         """Return an instance based on the given primary key identifier,
          or raise an exception.
 
@@ -641,7 +641,7 @@ class AsyncSession(ReversibleProxy[Session]):
             identity_token=identity_token,
         )
 
-        if not result_obj:
+        if result_obj is None:
             raise async_exc.NoResultFound(
                 "No row was found when one was required"
             )
index d8250836466427cc5350f969c43b1cb46e07b8d3..aa7078304cc4749c7af9c1cffa6f499d573a1601 100644 (file)
@@ -3591,7 +3591,7 @@ class Session(_SessionClassMethods, EventTarget):
         identity_token: Optional[Any] = None,
         execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
         bind_arguments: Optional[_BindArguments] = None,
-    ) -> Optional[_O]:
+    ) -> _O:
         """Return exactly one instance based on the given primary key identifier,
            or raise an exception.
 
@@ -3601,9 +3601,9 @@ class Session(_SessionClassMethods, EventTarget):
 
             my_user = session.get_one(User, 5)
 
-            some_object = session.get(VersionedFoo, (5, 10))
+            some_object = session.get_one(VersionedFoo, (5, 10))
 
-            some_object = session.get(
+            some_object = session.get_one(
                 VersionedFoo,
                 {"id": 5, "version_id": 10}
             )
@@ -3635,7 +3635,7 @@ class Session(_SessionClassMethods, EventTarget):
          the most expedient.  If the primary key of a row is the value "5",
          the call looks like::
 
-            my_object = session.get(SomeClass, 5)
+            my_object = session.get_one(SomeClass, 5)
 
          The tuple form contains primary key values typically in
          the order in which they correspond to the mapped
@@ -3647,14 +3647,14 @@ class Session(_SessionClassMethods, EventTarget):
          of a row is represented by the integer
          digits "5, 10" the call would look like::
 
-             my_object = session.get(SomeClass, (5, 10))
+             my_object = session.get_one(SomeClass, (5, 10))
 
          The dictionary form should include as keys the mapped attribute names
          corresponding to each element of the primary key.  If the mapped class
          has the attributes ``id``, ``version_id`` as the attributes which
          store the object's primary key value, the call would look like::
 
-            my_object = session.get(SomeClass, {"id": 5, "version_id": 10})
+            my_object = session.get_one(SomeClass, {"id": 5, "version_id": 10})
 
         :param options: optional sequence of loader options which will be
          applied to the query, if one is emitted.
@@ -3696,7 +3696,7 @@ class Session(_SessionClassMethods, EventTarget):
             bind_arguments=bind_arguments,
         )
 
-        if not impl:
+        if impl is None:
             raise sa_exc.NoResultFound(
                 "No row was found when one was required"
             )