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

Warnings are thrown since last version #103

Open
Tsumiki-Chan opened this issue Sep 2, 2016 · 13 comments
Open

Warnings are thrown since last version #103

Tsumiki-Chan opened this issue Sep 2, 2016 · 13 comments
Labels
enhancement pymysql-port Awaiting or implementing port of PyMySQL change
Milestone

Comments

@Tsumiki-Chan
Copy link

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?

@jettify
Copy link
Member

jettify commented Sep 5, 2016

thanks for report! I will take a look

@Reonaydo
Copy link
Contributor

Reonaydo commented Aug 9, 2017

Theese messages are very annoing.

This "Warning" was added in commit 0202d23

@TECHNOFAB11
Copy link

Just seen this too. Quite annoying indeed :)

@terricain
Copy link
Collaborator

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

@webknjaz
Copy link
Member

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

@TECHNOFAB11
Copy link

TECHNOFAB11 commented Jan 27, 2020

@webknjaz A how would be appreciated :P

@webknjaz
Copy link
Member

webknjaz commented Jan 27, 2020

@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
Copy link
Member

@wallneradam
Copy link

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")

@rspadim
Copy link

rspadim commented Jun 13, 2020

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

@diwu1989
Copy link

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.

@Nothing4You
Copy link
Collaborator

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 Nothing4You added the pymysql-port Awaiting or implementing port of PyMySQL change label Jan 30, 2022
@Nothing4You Nothing4You added this to the 1.0 milestone Jan 30, 2022
@Nothing4You Nothing4You modified the milestones: 0.1, 1.0 Feb 18, 2022
@Nothing4You
Copy link
Collaborator

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 PyMySQL/PyMySQL#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pymysql-port Awaiting or implementing port of PyMySQL change
Projects
None yet
Development

No branches or pull requests

10 participants