tisboyo / Twitch_Bot

4 stars 2 forks source link

Crash when users subscribes without being in Users table #241

Closed tisboyo closed 3 years ago

tisboyo commented 3 years ago

twitchbot_bot | proton_fig(baldengineer): god morgon twitchbot_bot | New chatter proton_fig sent to MQTT. twitchbot_bot | twitchbot_bot | error has occurred while triggering a event on a mod, details: twitchbot_bot | mod: twitchlog twitchbot_bot | event: Event.on_pubsub_subscription twitchbot_bot | error: <class 'sqlalchemy.exc.IntegrityError'> twitchbot_bot | reason: (mysql.connector.errors.IntegrityError) 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (twitchbot.subscriptions, CONSTRAINT subscriptions_ibfk_2 FOREIGN KEY (user_id) REFERENCES users (user_id)) twitchbot_bot | [SQL: INSERT INTO subscriptions (user_id, channel, subscription_level, cumulative_months, streak_months) VALUES (%(user_id)s, %(channel)s, %(subscription_level)s, %(cumulative_months)s, %(streak_months)s )] twitchbot_bot | [parameters: {'user_id': '715169982', 'channel': '125957551', 'subscription_level': 'Prime', 'cumulative_months': 1, 'streak_months': 0}] twitchbot_bot | (Background on this error at: https://sqlalche.me/e/14/gkpj) twitchbot_bot | stack trace: twitchbot_bot | Traceback (most recent call last): twitchbot_bot | File "/usr/local/lib/python3.9/site-packages/mysql/connector/connection_cext.py", line 513, in cmd_query twitchbot_bot | self._cmysql.query(query, twitchbot_bot | _mysql_connector.MySQLInterfaceError: Cannot add or update a child row: a foreign key constraint fails (twitchbot.subscriptions, CONSTRAINT subscriptions_ibfk_2 FOREIGN KEY (user_id) REFERENCES users (user_id))

Users very first action in the channel was a subscription and therefor was never inserted into the users table before hand, causing an sql error. Similar to the gift sub problem, but not the same.