Is 'transaction' reserved? #4113
-
I am following: https://docs.litestar.dev/2/tutorials/sqlalchemy/1-provide-session-with-di.html @get("/sqlite")
async def get_list(transaction:AsyncSession) -> RecordCollection | dict[str, str]:
logger.info("Access to get_list route detected.")
results = [serialize_record(todo) for todo in await get_all_records(transaction)]
if not results:
return {"success": "No records found."}
return results
app = Litestar(route_handlers=[index, upload_file, log_file, get_list],
logging_config=logging_config,
lifespan=[db_connection],
dependencies={"transaction":provide_transaction}
) This runs fine, however, if I rename "transaction" into something like "active_session" the program fails. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
transaction
is defined as a dependency (dependencies={"transaction":provide_transaction}
). It will be injected under the key it's defined at. If you want to use a different key, you'll have to rename it in the dependency declaration as well as the function where it's being used.