Skip to content

Commit d063f68

Browse files
authored
Remove auto show warnings (#774)
1 parent 34adc28 commit d063f68

File tree

4 files changed

+0
-92
lines changed

4 files changed

+0
-92
lines changed

pymysql/cursors.py

-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import print_function, absolute_import
33
from functools import partial
44
import re
5-
import warnings
65

76
from ._compat import range_type, text_type, PY2
87
from . import err
@@ -35,8 +34,6 @@ class Cursor(object):
3534
#: Default value of max_allowed_packet is 1048576.
3635
max_stmt_length = 1024000
3736

38-
_defer_warnings = False
39-
4037
def __init__(self, connection):
4138
self.connection = connection
4239
self.description = None
@@ -46,7 +43,6 @@ def __init__(self, connection):
4643
self._executed = None
4744
self._result = None
4845
self._rows = None
49-
self._warnings_handled = False
5046

5147
def close(self):
5248
"""
@@ -90,9 +86,6 @@ def _nextset(self, unbuffered=False):
9086
"""Get the next query set"""
9187
conn = self._get_db()
9288
current_result = self._result
93-
# for unbuffered queries warnings are only available once whole result has been read
94-
if unbuffered:
95-
self._show_warnings()
9689
if current_result is None or current_result is not conn._result:
9790
return None
9891
if not current_result.has_next:
@@ -347,26 +340,6 @@ def _do_get_result(self):
347340
self.description = result.description
348341
self.lastrowid = result.insert_id
349342
self._rows = result.rows
350-
self._warnings_handled = False
351-
352-
if not self._defer_warnings:
353-
self._show_warnings()
354-
355-
def _show_warnings(self):
356-
if self._warnings_handled:
357-
return
358-
self._warnings_handled = True
359-
if self._result and (self._result.has_next or not self._result.warning_count):
360-
return
361-
ws = self._get_db().show_warnings()
362-
if ws is None:
363-
return
364-
for w in ws:
365-
msg = w[-1]
366-
if PY2:
367-
if isinstance(msg, unicode):
368-
msg = msg.encode('utf-8', 'replace')
369-
warnings.warn(err.Warning(*w[1:3]), stacklevel=4)
370343

371344
def __iter__(self):
372345
return iter(self.fetchone, None)
@@ -427,8 +400,6 @@ class SSCursor(Cursor):
427400
possible to scroll backwards, as only the current row is held in memory.
428401
"""
429402

430-
_defer_warnings = True
431-
432403
def _conv_row(self, row):
433404
return row
434405

@@ -468,7 +439,6 @@ def fetchone(self):
468439
self._check_executed()
469440
row = self.read_next()
470441
if row is None:
471-
self._show_warnings()
472442
return None
473443
self.rownumber += 1
474444
return row
@@ -502,7 +472,6 @@ def fetchmany(self, size=None):
502472
for i in range_type(size):
503473
row = self.read_next()
504474
if row is None:
505-
self._show_warnings()
506475
break
507476
rows.append(row)
508477
self.rownumber += 1

pymysql/tests/test_basic.py

-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import datetime
33
import json
44
import time
5-
import warnings
65

76
import pytest
87

@@ -378,14 +377,3 @@ def test_issue_288(self):
378377
age = values(age)"""))
379378
cursor.execute('commit')
380379
self._verify_records(data)
381-
382-
def test_warnings(self):
383-
con = self.connect()
384-
cur = con.cursor()
385-
with warnings.catch_warnings(record=True) as ws:
386-
warnings.simplefilter("always")
387-
cur.execute("drop table if exists no_exists_table")
388-
self.assertEqual(len(ws), 1)
389-
self.assertEqual(ws[0].category, pymysql.Warning)
390-
if u"no_exists_table" not in str(ws[0].message):
391-
self.fail("'no_exists_table' not in %s" % (str(ws[0].message),))

pymysql/tests/test_issues.py

-25
Original file line numberDiff line numberDiff line change
@@ -485,28 +485,3 @@ def test_issue_363(self):
485485
# don't assert the exact internal binary value, as it could
486486
# vary across implementations
487487
self.assertTrue(isinstance(row[0], bytes))
488-
489-
def test_issue_491(self):
490-
""" Test warning propagation """
491-
conn = pymysql.connect(charset="utf8", **self.databases[0])
492-
493-
with warnings.catch_warnings():
494-
# Ignore all warnings other than pymysql generated ones
495-
warnings.simplefilter("ignore")
496-
warnings.simplefilter("error", category=pymysql.Warning)
497-
498-
# verify for both buffered and unbuffered cursor types
499-
for cursor_class in (cursors.Cursor, cursors.SSCursor):
500-
c = conn.cursor(cursor_class)
501-
try:
502-
c.execute("SELECT CAST('124b' AS SIGNED)")
503-
c.fetchall()
504-
except pymysql.Warning as e:
505-
# Warnings should have errorcode and string message, just like exceptions
506-
self.assertEqual(len(e.args), 2)
507-
self.assertEqual(e.args[0], 1292)
508-
self.assertTrue(isinstance(e.args[1], text_type))
509-
else:
510-
self.fail("Should raise Warning")
511-
finally:
512-
c.close()

pymysql/tests/test_load_local.py

-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pymysql.tests import base
33

44
import os
5-
import warnings
65

76
__all__ = ["TestLoadLocal"]
87

@@ -64,29 +63,6 @@ def test_unbuffered_load_file(self):
6463
c = conn.cursor()
6564
c.execute("DROP TABLE test_load_local")
6665

67-
def test_load_warnings(self):
68-
"""Test load local infile produces the appropriate warnings"""
69-
conn = self.connect()
70-
c = conn.cursor()
71-
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
72-
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
73-
'data',
74-
'load_local_warn_data.txt')
75-
try:
76-
with warnings.catch_warnings(record=True) as w:
77-
warnings.simplefilter('always')
78-
c.execute(
79-
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
80-
"test_load_local FIELDS TERMINATED BY ','").format(filename)
81-
)
82-
self.assertEqual(w[0].category, Warning)
83-
expected_message = "Incorrect integer value"
84-
if expected_message not in str(w[-1].message):
85-
self.fail("%r not in %r" % (expected_message, w[-1].message))
86-
finally:
87-
c.execute("DROP TABLE test_load_local")
88-
c.close()
89-
9066

9167
if __name__ == "__main__":
9268
import unittest

0 commit comments

Comments
 (0)