-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
Signed-off-by: Sylvain Leclerc <[email protected]>
Signed-off-by: Sylvain Leclerc <[email protected]>
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() |
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 imagine there's not a way to do this in a cleaner way (check of class instance) :/ ?
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.
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.
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.
Ok I see
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 changed the logic to depend on the driver name instead, it should be a little more reliable than class names.
Signed-off-by: Sylvain Leclerc <[email protected]>
Signed-off-by: Sylvain Leclerc <[email protected]>
This fixes the issue we encountered since PR #2172 where we couldn't delete studies on our local env or inside desktop version
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.