aiomysql icon indicating copy to clipboard operation
aiomysql copied to clipboard

Warnings are thrown since last version

Open Tsumiki-Chan opened this issue 7 years ago • 13 comments

Since I updated to the latest version aiomysql throws me warnings when I use a "IF NOT EXISTS" or "IGNORE" statement instead of just discarding them

/usr/local/lib/python3.5/dist-packages/aiomysql/cursors.py:461: Warning: Can't create database 'srv_163305530364788736'; database exists
  yield from self._do_get_result()

Executed code: await cur.execute("CREATE DATABASE IF NOT EXISTS srv_163305530364788736;")

Is there any way to tell aiomysql/pymysql to just discard this?

Tsumiki-Chan avatar Sep 02 '16 21:09 Tsumiki-Chan

thanks for report! I will take a look

jettify avatar Sep 05 '16 11:09 jettify

Theese messages are very annoing.

This "Warning" was added in commit 0202d230f458334c89c3f852f63340f7ff23f3f8

Reonaydo avatar Aug 09 '17 09:08 Reonaydo

Just seen this too. Quite annoying indeed :)

TECHNOFAB11 avatar Jun 10 '19 15:06 TECHNOFAB11

@jettify should we add an option to suppress warnings / make them opt-in?

terricain avatar Jun 10 '19 19:06 terricain

Users can easily suppress warnings using Python stdlib already, no need for switches, they'd only complicate the codebase

webknjaz avatar Jun 13 '19 09:06 webknjaz

@webknjaz A how would be appreciated :P

TECHNOFAB11 avatar Jan 27 '20 15:01 TECHNOFAB11

@TECHNOFAB11 python -W when just running your code and filterwarnings in pytest — use error for any warning and cherry-pick a few ignored onces.

webknjaz avatar Jan 27 '20 17:01 webknjaz

Example: https://github.com/python-trio/snekomatic/blob/316f5c0/pytest.ini#L4-L9

webknjaz avatar Jan 27 '20 17:01 webknjaz

If anybody has this problem, it is how you can filter annoying warnings:

import warnings
# Suppress warnings only for aiomysql, all other modules can send warnings
warnings.filterwarnings('ignore', module=r"aiomysql")
...
# Enable warnings again
warnings.filterwarnings('default', module=r"aiomysql")

wallneradam avatar May 27 '20 15:05 wallneradam

or use another function to warnings:

import warnings
def somefunction(message, category, filename, lineno, file=None, line=None):
    logger.warning("warning_wrapper message", extra={
        "warn_message": message,
        "warn_category": category,
        "warn_filename": filename,
        "warn_file": file,
        "warn_lineno": lineno,
        "warn_line": line
    })
warnings._show_warning = somefunction

rspadim avatar Jun 13 '20 14:06 rspadim

It's not just about not showing the warnings though, the extra round trip SQL to execute and read the result set adds overhead.

So being able to disable it altogether is still useful.

diwu1989 avatar Oct 13 '20 21:10 diwu1989

PyMySQL stopped showing warnings by default in 0.10.0:

MySQL warnings are not shown by default because many user report issue to PyMySQL issue tracker when they see warning. You need to call "SHOW WARNINGS" explicitly when you want to see warnings.

we should do the same.

Nothing4You avatar Jan 30 '22 09:01 Nothing4You

I don't think warnings should be removed without replacement. Since MySQL already tells us the warning count in the response we should at least expose it.

I've just created https://github.com/PyMySQL/PyMySQL/pull/1056 and plan to port this functionality to aiomysql afterwards.

I'm not yet entirely sure I want fully remove the functionality to raise warnings, but if they're kept it should be configurable whether they're raised.

Nothing4You avatar Jul 11 '22 00:07 Nothing4You