@@ -802,39 +802,46 @@ async def _execute_and_fetch(conn, query):
802
802
lookup_conds = [
803
803
c == last_row_id
804
804
if c is table ._autoincrement_column
805
- else c == _cast_json (
806
- c , compiled_params .get (key_getter (c ), None ))
805
+ else c
806
+ == _cast_json ( c , compiled_params .get (key_getter (c ), None ))
807
807
for c in table .primary_key
808
808
]
809
809
else :
810
810
lookup_conds = [
811
- c == _cast_json (
812
- c , compiled_params .get (key_getter (c ), None ))
811
+ c == _cast_json (c , compiled_params .get (key_getter (c ), None ))
813
812
for c in table .columns
814
813
]
815
- query = sa .select (table .columns ).where (
816
- sa .and_ (* lookup_conds )).execution_options (** execution_opts )
814
+ query = (
815
+ sa .select (table .columns )
816
+ .where (sa .and_ (* lookup_conds ))
817
+ .execution_options (** execution_opts )
818
+ )
817
819
row = await conn .first (query )
818
820
elif context .isupdate :
819
821
if context .get_affected_rows () == 0 :
820
822
raise NoSuchRowError ()
821
823
table = context .compiled .statement .table
822
824
if len (table .primary_key ) > 0 :
823
825
lookup_conds = [
824
- c == _cast_json (
825
- c , item .__values__ [
826
- item ._column_name_map .invert_get (c .name )])
826
+ c
827
+ == _cast_json (
828
+ c , item .__values__ [item ._column_name_map .invert_get (c .name )]
829
+ )
827
830
for c in table .primary_key
828
831
]
829
832
else :
830
833
lookup_conds = [
831
- c == _cast_json (
832
- c , item .__values__ [
833
- item ._column_name_map .invert_get (c .name )])
834
+ c
835
+ == _cast_json (
836
+ c , item .__values__ [item ._column_name_map .invert_get (c .name )]
837
+ )
834
838
for c in table .columns
835
839
]
836
- query = sa .select (table .columns ).where (
837
- sa .and_ (* lookup_conds )).execution_options (** execution_opts )
840
+ query = (
841
+ sa .select (table .columns )
842
+ .where (sa .and_ (* lookup_conds ))
843
+ .execution_options (** execution_opts )
844
+ )
838
845
row = await conn .first (query )
839
846
return row
840
847
@@ -851,7 +858,8 @@ async def _execute_and_fetch(conn, query):
851
858
852
859
def _cast_json (column , value ):
853
860
# FIXME: for MySQL, json string in WHERE clause needs to be cast to JSON type
854
- if (isinstance (column .type , sa .JSON ) or
855
- isinstance (getattr (column .type , 'impl' , None ), sa .JSON )):
861
+ if isinstance (column .type , sa .JSON ) or isinstance (
862
+ getattr (column .type , "impl" , None ), sa .JSON
863
+ ):
856
864
return sa .cast (value , sa .JSON )
857
865
return value
0 commit comments