4 ms·
Yeah our org should really move away from flask-sqlalchemy and be more declarative about what session changes should actually be made on. Being more hands on w
by Topgamer7 6y ago
Yeah our org should really move away from flask-sqlalchemy and be more declarative about what session changes should actually be made on.
Being more hands on with sqlalchemy is probably the right approach.
- danjac 6y agoNot having touched this stack in a while: what is best current practice for wiring together sqlalchemy and flask (including unit tests)?
- returningfory2 6y agoPotentially don't wire them together? That is, isolate them in separate parts of the code. I always found Flask-SQLAlchemy a strange approach because it ties opposite and somewhat orthogonal parts of the request lifecycle together. When requests-to-data-transactions is a 1-1 relationship it's a convenience, but once you step out of that I think it's better to do things by hand. My main app has a simple layer structure of "request > business logic > data layer". All of the business logic functions start a SQLAlchemy transaction using a Python decorator that is ~10 lines of SQLAlchemy code.
- ergo14 6y agoCheck out how things are wired with in this Pyramid cookie cutter. https://github.com/Pylons/pyramid-cookiecutter-starter/blob/latest/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.repo_name%7D%7D/sqlalchemy_models/__init__.py https://github.com/Pylons/pyramid-cookiecutter-starter/blob/... I think same approach should work well for flask - just tie the session to the request object on first access. Side note: I think we met on IRC few years ago ;-)
- luhn 6y agoThere is a lot going on in that cookie cutter. The “transaction” library for transaction management, wired into Pyramid with pyramid_tm, wired into SQLAlchemy with zope.sqlalchemy. Works nicely for Pyramid, but I don’t know how that translates to Flask.
- jononor 6y agoI passed on flask-sqlalchemy because it was not obvious to me how it worked together, and I did not see the value over just using Flask and SQLAlchemy with no special integration. Has worked now a couple of years in, will see how it is in a few years more.