We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7f84d4c commit 1cd0aabCopy full SHA for 1cd0aab
1 file changed
tests/conftest.py
@@ -140,9 +140,18 @@ def get_or_create_db_entry(
140
conditions = [
141
getattr(table, key) == value for key, value in lookup_kwargs.items()
142
]
143
- entry = (
144
- session.execute(select(table).where(and_(*conditions))).scalars().first()
145
- )
+ # Use 'exec()' for SQLModel sessions
+ if isinstance(session, SQLModelSession):
+ 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")
155
if entry:
156
return entry
157
0 commit comments