Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Specify custom session class #327
SQLAlchemy allows us to use custom session classes in case we wanna override default behavior:
sqlalchemy.orm.scoped_session( sqlalchemy.orm.sessionmaker( autocommit=False, autoflush=False, bind=self.engine, class_=NoDeleteSession # Custom session class ) )
This is critical, as in most business programs operations like
class NoDeleteSession(sqlalchemy.orm.session.Session): def __init__(self, bind=None, autoflush=True, expire_on_commit=True, _enable_transaction_accounting=True, autocommit=False, twophase=False, weak_identity_map=True, binds=None, extension=None, info=None, query_cls=sqlalchemy.orm.query.Query): self._persist_deleted = set() super(NoDeleteSession, self).__init__( bind=bind, autoflush=autoflush, expire_on_commit=expire_on_commit, _enable_transaction_accounting=_enable_transaction_accounting, autocommit=autocommit, twophase=twophase, weak_identity_map=weak_identity_map, binds=binds, extension=extension, info=info, query_cls=query_cls ) def delete(self, instance): # Do not actually delete the instance. Set the is_deleted flag instead. instance.is_deleted = True self._persist_deleted.add(instance)
Going through the flask-sqlalchemy source code and documentation, it seems that this isn't currently supported. Can we have this functionality?