Last active
November 25, 2021 10:40
-
-
Save michaelbukachi/7554cd575b24092b8ac92b2c0bacefe7 to your computer and use it in GitHub Desktop.
Flask-Admin with `autocommit=True`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This workaround helps avoid: | |
sqlalchemy.exc.InvalidRequestError: No transaction is begun | |
whenever you try to create/update a model when `autocommit=True` | |
''' | |
class BaseModelView(ModelView): | |
def create_model(self, form): | |
self.session.begin() | |
super(BaseModelView, self).create_model(form) | |
def update_model(self, form, model): | |
self.session.begin() | |
super(BaseModelView, self).update_model(form, model) | |
def delete_model(self, model): | |
self.session.begin() | |
super(BaseModelView, self).delete_model(model) | |
# Rest of the code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I'm facing the same problem with autocommit + and Flask-admin explicit session-commits, but with your code I'm still getting the same "No transaction is begun" error. If I paste my code, would you be able to take a look at it?:)
Regards,