Open maxachis opened 5 months ago
@EvilDrPurple When we get further along, I'd like to look into SQLAlchemy's connection pooling functionality. #376 occurred in part because we only had one active connection being managed at a time, so having multiple connections in a connection pool might be a way to resolve the problem in a more thorough way than the one I offered for that issue.
This is not a remotely high priority at the moment, but something I wanted to keep on the radar for eventual exploration.
So after attempting to integrate the changes @EvilDrPurple made with the ones I'm making in #318, I identified a few issues that weren't immediately apparent when just looking at the SQLAlchemy changes in isolation:
DatabaseClient
is also impacted. app.py
as well as pytest tests and fixtures have to be changed, and sometimes substantially. This poses a problem when other already-substantial changes, such as #318, are also occurring at the same time. It's a lot of logic that all needs to be resolved simultaneously.Flask-SQLAlchemy
introduces a global variable which poses some additional issues -- this makes it harder to isolate tests, for example. It's possible that SQLAlchemy
alone would be more avoidable.The end result of all of this is that it turns out that even a piecemeal implementation of SQLAlchemy becomes considerably more difficult, because too much logic is tightly coupled in the code base at the moment to enable easy shifts to a new way of interacting with the database, and SQLAlchemy (or at least Flask-SQLAlchemy
) in particular encourages the use of global variables that make reconciling changes more challenging.
The way I see it, we have a few options here, taking into account the current limitations as well as that other, important changes like #318 are also in the pipeline:
@maxachis your instinct about priority is right—the auth work must continue so that API changes may continue. SQLAlchemy is a good idea, but...but. It does make sense that it wouldn't play nice with Psycopg2, and it seems like Psycopg2 would be made unnecessary with SQLAlchemy?
@maxachis your instinct about priority is right—the auth work must continue so that API changes may continue. SQLAlchemy is a good idea, but...but. It does make sense that it wouldn't play nice with Psycopg2, and it seems like Psycopg2 would be made unnecessary with SQLAlchemy?
Exactly. We only need Psycopg2 or SQLAlchemy, and the only reason for having both is because we're transitioning from one to the other. But part of that transition is that we want to minimize the friction in that transition, and have as little be upset as possible.
I do want to get @EvilDrPurple 's feedback on this, but my sense is that we will need to rollback. It's one thing if we only have to change some functions in DatabaseClient and maybe a few other limited areas, but it's another thing if changes to DatabaseClient necessitate considerable changes to app.py
, the tests, and the fixtures.
On a long enough timescale, the time spent overhauling everything to SQLAlchemy right now would eventually, I believe, pay for itself. But currently our timescale is short because we want to get v2 out the door!
ok! As the two back end devs, y'all have my permission to make the transition abrupt/friction-ful, because we're protected by the fork and dev environment. Thanks for thinking this through.
Alright! For the moment, we are reverted, and @EvilDrPurple is going to look into a more modular approach while I work on auth!
Current plan is as follows:
SQLAlchemy is an Object-Relational Mapping (ORM) tool that represents SQL database actions in Python code.
Why use SQLAlchemy?
Why not use SQLAlchemy?
My thoughts
Resources: