]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update case statement to v2 syntax
authorFederico Caselli <cfederico87@gmail.com>
Fri, 24 Feb 2023 20:32:46 +0000 (21:32 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 24 Feb 2023 20:33:47 +0000 (21:33 +0100)
Change-Id: If278ea170e0a17b1e8ace2d470fb2fbdb7a6e9c1
References: #9370
References: #9365

doc/build/orm/mapped_sql_expr.rst
examples/nested_sets/nested_sets.py
examples/vertical/dictlike-polymorphic.py

index 4751148133b0f30a31f3a749e878a5529686e3d7..357949c8feeeb993d0e3ac6f600d5bf33bb58e93 100644 (file)
@@ -71,9 +71,7 @@ needs to be present inside the hybrid, using the ``if`` statement in Python and
         @fullname.expression
         def fullname(cls):
             return case(
-                [
-                    (cls.firstname != None, cls.firstname + " " + cls.lastname),
-                ],
+                (cls.firstname != None, cls.firstname + " " + cls.lastname),
                 else_=cls.lastname,
             )
 
index 0450551f380ed51cb03d92490c49d0cea95df66b..2412eaf9ece57e3c4b9b758e6dfca1dc0c2342c5 100644 (file)
@@ -54,21 +54,17 @@ def before_insert(mapper, connection, instance):
         connection.execute(
             personnel.update(personnel.c.rgt >= right_most_sibling).values(
                 lft=case(
-                    [
-                        (
-                            personnel.c.lft > right_most_sibling,
-                            personnel.c.lft + 2,
-                        )
-                    ],
+                    (
+                        personnel.c.lft > right_most_sibling,
+                        personnel.c.lft + 2,
+                    ),
                     else_=personnel.c.lft,
                 ),
                 rgt=case(
-                    [
-                        (
-                            personnel.c.rgt >= right_most_sibling,
-                            personnel.c.rgt + 2,
-                        )
-                    ],
+                    (
+                        personnel.c.rgt >= right_most_sibling,
+                        personnel.c.rgt + 2,
+                    ),
                     else_=personnel.c.rgt,
                 ),
             )
index 0343d53e1212e856f1a23bd4484a1e2c2fa6cc2f..afd23c4e1c20f48017bfaeb2e37158073e72c011 100644 (file)
@@ -83,7 +83,7 @@ class PolymorphicVerticalProperty:
                 for attribute, discriminator in pairs
                 if attribute is not None
             ]
-            return case(whens, value=self.cls.type, else_=null())
+            return case(*whens, value=self.cls.type, else_=null())
 
         def __eq__(self, other):
             return self._case() == cast(other, String)