Replies: 1 comment 4 replies
-
Well, what you could do is just to have separate modules for DB initialization on one side, and FastAPI Users on the other side, and import them whenever you need it. I've created a working Repl.it example to show you: |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
Details in this StackOverflow question. Essentially, fastapi-users relies on a MongoDB client instance, which could be set up globally in one's
main.py
. However, if I want to split up my app into Router files, each file would need to be able to get this MongoDB Client object (rather than making a new one) to ensure it's all working in the same thread. This would be done using a FastAPIstartup
trigger. Because such Router endpoints rely on fastapi-users for auth, then I need to somehow instantiate that in main.py too, which doesn't yet have access to a DB client object since it won't be made until the app has started up.To Reproduce
Steps to reproduce the behavior:
startup
trigger to make MongoDB clientExpected behavior
Allow
FastAPIUsers()
to take a DB-contention-generating function rather than a DB connection itself (ie a sort of promise)Configuration
Beta Was this translation helpful? Give feedback.
All reactions