Open molitoris opened 4 years ago
Please use the answer by @michaelbukachi cause mine was deprecated.
You could implement the adapter in the libary or create a custom db adapter. Example Custom DB Adapter:
# Define a CustomDbAdapter from flask_user.db_adapters import DbAdapterInterface class CustomDbAdapter(DbAdapterInterface): ... # Setup Flask-User user_manager = UserManager(app, db, User) # Customize Flask-User user_manager.db_adapter = CustomDbAdapter(app)
I've gone through the source code and the db_adapter is not used anywhere in UserManager
.
This is the workaround I had to use:
user_manager.init_app(app, db, User)
db_manager = DBManager(app, db, User)
db_manager.db_adapter = CustomDbAdapter(app, db)
user_manager.db_manager = db_manager
I would like to use MongoEngine instead of Flask_MongoEngine since the second seems unsupported.
The documentation explained how to create a custom
db_adapter
. It my case, it should look like this:Unfortunately, I could not find a way how to add my own adapter. I think the problem is in
UserManager
. In the constructor ofUserManager
an instance ofDbManager
is created. The constructor ofDbManager
compares the passed database argument against the supported databases. In case it is not one of the supported databases, it throws an error. The error prevents the constructor ofUserManager
to complete.Solution
I think one could overcome this by adding an optional attribute
custom_db_adapter
to the constructor ofDbManager
. After checking if the adapter is an instance ofdb_adapter_interface
, thecustom_db_adapter
is passed toadpater
.Let me know and I will implement it and add a PR.
PS:
Flask-User
is an amazing library. All the adapters make a lot of sense and the documentation makes it very clear.