From c03e2bf950e95d3424c3616a063e108ae8664c62 Mon Sep 17 00:00:00 2001 From: prasad83 Date: Tue, 2 May 2023 20:13:38 +0530 Subject: [PATCH 1/2] Fixed query execute with params for Sqlachemy 2.0 Sqlachemy 2.x expects parameters be bound to statement (=text(query)) --- records.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/records.py b/records.py index 1fd6a93..2f83e54 100644 --- a/records.py +++ b/records.py @@ -357,7 +357,7 @@ class Connection(object): """ # Execute the given query. - cursor = self._conn.execute(text(query), **params) # TODO: PARAMS GO HERE + cursor = self._conn.execute(text(query).bindparams(**params)) # TODO: PARAMS GO HERE # Row-by-row Record generator. row_gen = (Record(cursor.keys(), row) for row in cursor) From 25ccf2e14d204e79a32fed2cb61e81069abc85c4 Mon Sep 17 00:00:00 2001 From: prasad83 Date: Tue, 2 May 2023 20:41:47 +0530 Subject: [PATCH 2/2] Fix for string based key lookup with sqlachemy 2.0 Should use wrapped _keys instead of keys() --- records.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/records.py b/records.py index 2f83e54..1f15a95 100644 --- a/records.py +++ b/records.py @@ -50,9 +50,12 @@ class Record(object): return self.values()[key] # Support for string-based lookup. - if key in self.keys(): - i = self.keys().index(key) - if self.keys().count(key) > 1: + usekeys = self.keys() + if hasattr(usekeys, "_keys"): # sqlalchemy 2.x uses (result.RMKeyView which has wrapped _keys as list) + usekeys = usekeys._keys + if key in usekeys: + i = usekeys.index(key) + if usekeys.count(key) > 1: raise KeyError("Record contains multiple '{}' fields.".format(key)) return self.values()[i]