aiomysql
aiomysql copied to clipboard
Warnings are thrown since last version
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?
thanks for report! I will take a look
Theese messages are very annoing.
This "Warning" was added in commit 0202d230f458334c89c3f852f63340f7ff23f3f8
Just seen this too. Quite annoying indeed :)
@jettify should we add an option to suppress warnings / make them opt-in?
Users can easily suppress warnings using Python stdlib already, no need for switches, they'd only complicate the codebase
@webknjaz A how would be appreciated :P
@TECHNOFAB11 python -W
when just running your code and filterwarnings
in pytest
— use error for any warning and cherry-pick a few ignored onces.
Example: https://github.com/python-trio/snekomatic/blob/316f5c0/pytest.ini#L4-L9
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")
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
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.
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.
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.