Skip to content

Commit 1cd0aab

Browse files
committed
'execute()' is deprecated for SQLModel Session objects, so use 'exec()' instead
1 parent 7f84d4c commit 1cd0aab

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,18 @@ def get_or_create_db_entry(
140140
conditions = [
141141
getattr(table, key) == value for key, value in lookup_kwargs.items()
142142
]
143-
entry = (
144-
session.execute(select(table).where(and_(*conditions))).scalars().first()
145-
)
143+
# Use 'exec()' for SQLModel sessions
144+
if isinstance(session, SQLModelSession):
145+
entry = session.exec(select(table).where(and_(*conditions))).first()
146+
# Use 'execute()' for SQLAlchemy sessions
147+
elif isinstance(session, SQLAlchemySession):
148+
entry = (
149+
session.execute(select(table).where(and_(*conditions)))
150+
.scalars()
151+
.first()
152+
)
153+
else:
154+
raise TypeError("Unexpected Session type")
146155
if entry:
147156
return entry
148157

0 commit comments

Comments
 (0)