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

INSERT IGNORE creates error log and try...except is unable to catch it. #800

Closed
1 task done
MCC2429 opened this issue Jun 9, 2022 · 3 comments
Closed
1 task done
Labels

Comments

@MCC2429
Copy link

MCC2429 commented Jun 9, 2022

Describe the bug

async def add_guild(self, guild_id, guild):
    async with self.bot.pool.acquire() as conn:
        cur = await conn.cursor()
    try:
        await cur.execute(
            "INSERT IGNORE INTO Guilds (guild_id, guild_name) VALUES (%s, %s);", (guild_id, str(guild),)
        )
        await cur.execute(
            "INSERT IGNORE INTO G_Hangman (guild_id) VALUE (%s);", (guild_id,)
        )
    except (aiomysql.Error, aiomysql.Warning, mariadb.Warning, mariadb.Error) as e:
        print(f"ERROR = {e}")

Even though there is an ignore statement, the log still catches the Duplicate Entry warning for Primary Key.
This is for a Discord game, and each time a game starts, this function runs, and outputs a line per member of the server which can result in thousands of lines on the console that are unnecessary and get in the way of the necessary output.

With the "except" statement, I have tried individual errors, combinations, IntegrityErrors, DatabaseError, and anything that could be related to the log being caught. It seems that the error handling is not able to catch the error. This COULD be a me problem, but it seems unlikely at this point based on what I've tried.

To Reproduce

I use PyCharm to test out the code before uploading it to a hosting software.
async def add_guild(self, guild_id, guild):
async with self.bot.pool.acquire() as conn:
cur = await conn.cursor()
try:
await cur.execute(
"INSERT IGNORE INTO Guilds (guild_id, guild_name) VALUES (%s, %s);", (guild_id, str(guild),)
)
await cur.execute(
"INSERT IGNORE INTO G_Hangman (guild_id) VALUE (%s);", (guild_id,)
)
except (aiomysql.Error, aiomysql.Warning, mariadb.Warning, mariadb.Error) as e:
print(f"ERROR = {e}")

Regardless of the error handling or "IGNORE" parameter in the query, the console prints a duplicate entry warning.
Warning: Duplicate entry 'xxxx-xxxx' for key 'PRIMARY'
await self._query(query)
(removed ID's to prevent doxxing)

Expected behavior

WIth the Ignore statement, I expected no output for the duplicate entries.

With the exception, I tried to catch it as a variable to see if it worked, however, it was not caught.

Logs/tracebacks

C:\Users\macke\Documents\Kambot\venv\lib\site-packages\aiomysql\cursors.py:239: Warning: Duplicate entry 'xxxxx-xxxxx' for key 'PRIMARY'
  await self._query(query)
(removed ID's to prevent doxxing)

Python Version

Python 3.10.2

aiomysql Version

Name: aiomysql
Version: 0.1.1                                 
Summary: MySQL driver for asyncio.             
Home-page: https://github.com/aio-libs/aiomysql
Author: Nikolay Novik                          
Author-email: nickolainovik@gmail.com          
License: MIT
Location: c:\users\macke\documents\kambot\venv\lib\site-packages
Requires: PyMySQL
Required-by:

PyMySQL Version

Name: PyMySQL
Version: 1.0.2
Summary: Pure Python MySQL Driver
Home-page: https://github.com/PyMySQL/PyMySQL/
Author: yutaka.matsubara
Author-email: yutaka.matsubara@gmail.com
License: "MIT"
Location: c:\users\macke\documents\kambot\venv\lib\site-packages
Requires:
Required-by: aiomysql

SQLAlchemy Version

$ python -m pip show sqlalchemy

OS

Windows for the testing environment and Linux for the live environment.

Database type and version

10.6.8-MariaDB-1:10.6.8+maria~focal

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@MCC2429 MCC2429 added the bug label Jun 9, 2022
@MCC2429
Copy link
Author

MCC2429 commented Jun 12, 2022

I meant to add this when I first posted, I apologize, not meaning to bump, but I came to look. If I'm just doing something wrong, I'm more than happy to be told so, I just don't know what I'm doing wrong if I am.

@Nothing4You
Copy link
Collaborator

Hi,

warnings are not exceptions, you can't catch them with try ... catch.

See #103 for more information on this, there's a few workarounds listed there, as aiomysql does not yet provide a way to disable them.

@Nothing4You Nothing4You closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2022
@MCC2429
Copy link
Author

MCC2429 commented Jun 12, 2022

Thank you for the info and link! Sorry for the incorrect post!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants