Skip to content
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

fix: enable foreign keys for sqlite #2172

Merged
merged 5 commits into from
Oct 8, 2024
Merged

Conversation

sylvlecl
Copy link
Member

@sylvlecl sylvlecl commented Oct 7, 2024

By default, sqlite does not enforce foreign key constraints, this needs to be enabled explicitly.

This is in particular important to catch those errors in our unit tests, but also for
desktop mode.

Note
I have checked that indeed, tests before this fix did not pass.

MartinBelthle
MartinBelthle previously approved these changes Oct 7, 2024
def _is_sqlite_connection(dbapi_connection: Any) -> bool:
cls = dbapi_connection.__class__
full_classe_name = f"{cls.__module__}{cls.__name__}"
return "sqlite" in full_classe_name.lower()
Copy link
Contributor

@MartinBelthle MartinBelthle Oct 7, 2024

Choose a reason for hiding this comment

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

I imagine there's not a way to do this in a cleaner way (check of class instance) :/ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Check of class instance will be more fragile, this is kind of an implementation detail of sqlalchemy driver, I prefer being robust to any implementation change.
It's unlikely that another driver will have sqlite in its name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the logic to depend on the driver name instead, it should be a little more reliable than class names.

@sylvlecl sylvlecl merged commit f2460fe into dev Oct 8, 2024
11 checks passed
@sylvlecl sylvlecl deleted the fix/enforce-sqlite-foreign-keys branch October 8, 2024 07:45
sylvlecl pushed a commit that referenced this pull request Oct 11, 2024
This fixes the issue we encountered since PR
#2172 where we
couldn't delete studies on our local env or inside desktop version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants