-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add alembic tests #241
Add alembic tests #241
Conversation
Ok, so I couldn't find an elegant solution to the above problem, but it has something to do with calling this: from securedrop_client.db import Base
engine = somehow_make_engine_or_whatever()
Base.metadata.create_all(bind=engine) If this gets called before the alembic tests anywhere in the code, the generated SQL ends up being the above in the error, and the test fails. I can't figure out how or why this is happening. The solution was to split the alembic tests into a separate test fun using |
95f6b33
to
1225136
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @heartsucker, i'm pretty cool with this being merged (just a nit inline), but i do want to understand the one question I have inline re: alembic check constraints
alembic_schema = {k: v for k, v in alembic_schema.items() | ||
if k[2] != 'alembic_version'} | ||
|
||
assert_schemas_equal(alembic_schema, models_schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so with regard to the issue you describe in this PR, I took a look at this today and I don't understand the following: why do check constraints appear at all in the generated alembic schema? alembic claims that they can't autogenerate check constraints (they've got an open issue for it: sqlalchemy/alembic#508). do you understand why that is happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember looking in to this some time in the past. If I remember right, the check constraints for SQLite booleans (INT CHECK foo IN (0, 1)
type things) do work because they kinda have to otherwise the booleans just don't work at all. They are a special case that alembic does detect, but in general, check constraints that are explicitly defined are not detected.
b22e8b6
to
65a4073
Compare
Hey @heartsucker - Your PR looks good and the docs update is great 🎉 🎉 - since @redshiftzero already gave this a thorough review, I'm mostly interested in investigating the I was able to reproduce by removing the
Alembic CHECK contraintsI briefly looked into alembic CHECK constraints wondering if it wasn't fully implemented feature. I read that SQLAlchemy doesn’t "reflect CHECK constraints on any backend." And that SQLite CHECK constraints require manual migration. Before going down that rabbit hole, I looked to see if anything else looked 🐟 y Running tests in random order
To double check the test that is now passing, I manually compared the table schemas and saw that they matched:
ThoughtsInteresting how the CHECK constraint has been moved over after the change above. It makes it seem that this is indeed something alembic is capable of doing and that tests are just messing with the state somehow. Still strange behavior though. Why would only one constraint not be copied over? It'll take some time to track down which tests are stepping on each other's toes or if there's something wrong with the way pytest is setup. Probably best way to start is by studying the configuration changes made in this PR and look for any shared code like where db files are saved, etc. It would also be helpful to look into how tests are run when they're in separate files. |
This doesn't really affect us because these schemas are read back out from the SQLite DB. Also the boolean columns are a special case as an extra check constraint is generated by Alembic since SQLite doesn't have a boolean type, just int. |
(taken from SecureDrop core)
65a4073
to
08193f8
Compare
so I added two commits here which revert the separate run of the alembic tests (and CI is passing, but let me know if you disagree with any of the below and we can always drop my commits). here was my investigation process on this:
|
anyway i'm approving this but will let y'all @heartsucker and @creviera comment and merge when you are happy |
Fixes #203
Fixes #55
Fixes #170
Fixes #207
Requires #240 to be merged first otherwise this requires modification to get the migration up to date again.(edit: not true, these could be merged in any order)Bug (fixed, see comment below)
This Works
make test TESTS=tests/test_alembic.py
This Doesn't
make test
Comments
The error seems that something in the test suite is interfering with how sqlalchemy generates the
create_all()
DDL, and I cannot for the life of me figure it out.