Skip to content

Commit 24851a8

Browse files
authored
Update crud_router.py
1 parent 1e8ca19 commit 24851a8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/fastapi_quickcrud/crud_router.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,18 @@ def get_transaction_session():
108108

109109
if async_mode is None:
110110
async_mode = inspect.isasyncgen(db_session())
111-
if async_mode:
111+
112+
if sql_type is None:
112113
async def async_runner(f):
113114
return [i.bind.name async for i in f()]
114-
if sql_type is None:
115-
sql_type, = asyncio.get_event_loop().run_until_complete(async_runner(db_session))
116-
elif sql_type is None:
117-
sql_type, = [i.bind.name for i in db_session()]
115+
try:
116+
if async_mode:
117+
sql_type, = asyncio.get_event_loop().run_until_complete(async_runner(db_session))
118+
else:
119+
sql_type, = [i.bind.name for i in db_session()]
120+
except Exception:
121+
raise RuntimeError("Some unknown problem occurred error, maybe you are uvicorn.run with reload=True. "
122+
"Try declaring sql_type for crud_router_builder yourself using from fastapi_quickcrud.misc.type import SqlType")
118123

119124
if not crud_methods and NO_PRIMARY_KEY == False:
120125
crud_methods = CrudMethods.get_declarative_model_full_crud_method()

0 commit comments

Comments
 (0)