ItsDrike / code-jam-2024

Python Discord's Code Jam 2024, Contemplative Constellations Team
MIT License
1 stars 0 forks source link

Storing the sqlalchemy session in the bot has some wierd conscequences in case of sql error #66

Open Paillat-dev opened 1 month ago

Paillat-dev commented 1 month ago
PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.IntegrityError) UNIQUE constraint failed: user_list_items.list_id, user_list_items.tvdb_id, user_list_items.kind
[SQL: INSERT INTO user_list_items (list_id, tvdb_id, kind) VALUES (?, ?, ?)]
[parameters: (1, 385376, 'SERIES')]
(Background on this error at: https://sqlalche.me/e/20/gkpj) (Background on this error at: https://sqlalche.me/e/20/7s2a)
Paillat-dev commented 1 month ago

Session cannot be stored, it should be used w async with. Or some sort

ItsDrike commented 1 month ago

Hmm, well utils/database.py already has get_db_session async context-manager function, maybe we should just use that each time instead of just once in __main__.py

Paillat-dev commented 1 month ago

Yeah because I believe the __aexit__ cleans up stuff, and does rollbacks and things like this

ItsDrike commented 1 month ago

Sadly, this we didn't manage to fix this in time, however, it shouldn't affect the bot's functionalities, since we handle the sql errors ourselves, this doesn't propagate up, it's just that the handling isn't ideal.

ItsDrike commented 1 month ago

There is a post-deadline fix for this that was submitted in #75, it will not be merged into main as that would violate the code-jam's rules, however, I will leave the issue & PR opened just for reference.

Paillat-dev commented 1 month ago

Marked as priority medium, as sql errors should not happen - all sql errors happened while developement and were mitigated before they would hit the user.