Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5af8ece

Browse filesBrowse files
authored
Remove automatic warning check (PyMySQL#296)
1 parent 16915a0 commit 5af8ece
Copy full SHA for 5af8ece

File tree

Expand file treeCollapse file tree

2 files changed

+0
-68
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+0
-68
lines changed

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
-46Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class BaseCursor(object):
6161
InternalError, ProgrammingError, NotSupportedError,
6262
)
6363

64-
_defer_warnings = False
6564
connection = None
6665

6766
def __init__(self, connection):
@@ -126,40 +125,6 @@ def _check_executed(self):
126125
if not self._executed:
127126
raise ProgrammingError("execute() first")
128127

129-
def _warning_check(self):
130-
from warnings import warn
131-
db = self._get_db()
132-
133-
# None => warnings not interrogated for current query yet
134-
# 0 => no warnings exists or have been handled already for this query
135-
if self._warnings is None:
136-
self._warnings = db.warning_count()
137-
if self._warnings:
138-
# Only propagate warnings for current query once
139-
warning_count = self._warnings
140-
self._warnings = 0
141-
# When there is next result, fetching warnings cause "command
142-
# out of sync" error.
143-
if self._result and self._result.has_next:
144-
msg = "There are %d MySQL warnings." % (warning_count,)
145-
self.messages.append(msg)
146-
warn(self.Warning(0, msg), stacklevel=3)
147-
return
148-
149-
warnings = db.show_warnings()
150-
if warnings:
151-
# This is done in two loops in case
152-
# Warnings are set to raise exceptions.
153-
for w in warnings:
154-
self.messages.append((self.Warning, w))
155-
for w in warnings:
156-
warn(self.Warning(*w[1:3]), stacklevel=3)
157-
else:
158-
info = db.info()
159-
if info:
160-
self.messages.append((self.Warning, info))
161-
warn(self.Warning(0, info), stacklevel=3)
162-
163128
def nextset(self):
164129
"""Advance to the next result set.
165130
@@ -175,7 +140,6 @@ def nextset(self):
175140
return None
176141
self._do_get_result(db)
177142
self._post_get_result()
178-
self._warning_check()
179143
return 1
180144

181145
def _do_get_result(self, db):
@@ -248,8 +212,6 @@ def execute(self, query, args=None):
248212
query = query.encode(db.encoding, 'surrogateescape')
249213

250214
res = self._query(query)
251-
if not self._defer_warnings:
252-
self._warning_check()
253215
return res
254216

255217
def executemany(self, query, args):
@@ -363,8 +325,6 @@ def callproc(self, procname, args=()):
363325
if isinstance(q, unicode):
364326
q = q.encode(db.encoding, 'surrogateescape')
365327
self._query(q)
366-
if not self._defer_warnings:
367-
self._warning_check()
368328
return args
369329

370330
def _query(self, q):
@@ -470,8 +430,6 @@ class CursorUseResultMixIn(object):
470430
close() the cursor before additional queries can be performed on
471431
the connection."""
472432

473-
_defer_warnings = True
474-
475433
def _get_result(self):
476434
return self._get_db().use_result()
477435

@@ -480,7 +438,6 @@ def fetchone(self):
480438
self._check_executed()
481439
r = self._fetch_row(1)
482440
if not r:
483-
self._warning_check()
484441
return None
485442
self.rownumber = self.rownumber + 1
486443
return r[0]
@@ -491,16 +448,13 @@ def fetchmany(self, size=None):
491448
self._check_executed()
492449
r = self._fetch_row(size or self.arraysize)
493450
self.rownumber = self.rownumber + len(r)
494-
if not r:
495-
self._warning_check()
496451
return r
497452

498453
def fetchall(self):
499454
"""Fetchs all available rows from the cursor."""
500455
self._check_executed()
501456
r = self._fetch_row(0)
502457
self.rownumber = self.rownumber + len(r)
503-
self._warning_check()
504458
return r
505459

506460
def __iter__(self):

‎tests/test_MySQLdb_capabilities.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_capabilities.py
-22Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,6 @@ def test_reraise_exception(self):
160160
return
161161
self.fail("Should raise ProgrammingError")
162162

163-
def test_warning_propagation(self):
164-
with warnings.catch_warnings():
165-
# Ignore all warnings other than MySQLdb generated ones
166-
warnings.simplefilter("ignore")
167-
warnings.simplefilter("error", category=MySQLdb.Warning)
168-
169-
# verify for both buffered and unbuffered cursor types
170-
for cursor_class in (cursors.Cursor, cursors.SSCursor):
171-
c = self.connection.cursor(cursor_class)
172-
try:
173-
c.execute("SELECT CAST('124b' AS SIGNED)")
174-
c.fetchall()
175-
except MySQLdb.Warning as e:
176-
# Warnings should have errorcode and string message, just like exceptions
177-
self.assertEqual(len(e.args), 2)
178-
self.assertEqual(e.args[0], 1292)
179-
self.assertTrue(isinstance(e.args[1], unicode))
180-
else:
181-
self.fail("Should raise Warning")
182-
finally:
183-
c.close()
184-
185163
def test_binary_prefix(self):
186164
# verify prefix behaviour when enabled, disabled and for default (disabled)
187165
for binary_prefix in (True, False, None):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.