Skip to content

Conversation

@natkam
Copy link
Contributor

@natkam natkam commented Nov 20, 2025

Regarding the pragma enabling FKs: we can only register this event listener when the db backend is sqlite, because this pragma is sqlite-specific. With PostgreSQL, executing the pragma will cause an error.
I register the event listener based on the value of the DATABASE_TYPE env. var. - it probably would be better to actually get the sqlalchemy engine, or the GraderService's db_url, and check the dialect there... But I haven't managed to get it to work nicely yet.
UPDATE: I've figured out a better way. Seems to work as expected.

One more complication came up when I added a test that checks that the event listener works.
In the test environment, DATABASE_TYPE is not set, even though an sqlite database is used. We cannot set it "globally" , because some tests use a PostgreSQL database - and again, they would fail if the event listener was enabled.

Also: At the moment the migration tests (any many more!) would fail if we just enable the pragma in them all, because many of the tests would cause IntegrityErrors. And we do not have on delete behaviour configured for models related to other models via FKs; we'd have to add CASCADE to them all, I guess.

@natkam natkam force-pushed the fix/user-id-migrations branch from bbf79c6 to 8aeb783 Compare December 3, 2025 13:43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add this to a different file, since it is not a assignment handler test e.g. test_db.py or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. And I've also fixed some integrity errors in other tests and in migrations.

@natkam natkam merged commit 31c65d7 into release-0.9.1 Dec 5, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants