Skip to content

fix: check table existence before deleting sessions #2579

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

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

g-linville
Copy link
Member

Turns out that it was possible to get into a state where the user would get a 500 when trying to log out of all other sessions. This would happen if they had an identity tied to a previously configured but now deconfigured auth provider, so that sessions table didn't exist. This fixes that by checking for the table before we try to delete sessions from it.

Comment on lines 85 to 89
var exists bool
if err := db.Raw("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = ?)", tableName).Scan(&exists).Error; err != nil {
return false, err
}
return exists, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Does something like this work?

Suggested change
var exists bool
if err := db.Raw("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = ?)", tableName).Scan(&exists).Error; err != nil {
return false, err
}
return exists, nil
return db.Migrator().TableExists(tableName)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, this is much better, thanks

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville merged commit 7b44bf7 into obot-platform:main Apr 22, 2025
2 checks passed
@g-linville g-linville deleted the check-tables branch April 22, 2025 18:13
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