fetchall() should return empty sequence instead of None when no rows returned
Bug #480360 reported by
Ryan Williams
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MySQL Connector/Python |
Fix Released
|
Medium
|
Geert JM Vanderkelen |
Bug Description
>>> from mysql import connector
>>> conn = connector.
>>> curs = conn.cursor()
>>> curs.execute(
>>> print curs.fetchall()
None
This means that every piece of code that calls fetchall has to have a special case branch for None; if it returned an empty sequence, no special cases would be needed. This is probably also a minor violation of PEP-249. Easy to fix, though!
Changed in myconnpy: | |
status: | New → In Progress |
importance: | Low → Medium |
tags: | added: pep249 |
tags: | added: cursor |
Changed in myconnpy: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
This went from empty list to None a few times. PEP-249 says actually nothing what it should return in case of "empty" result set:
.fetchall()
Fetch all (remaining) rows of a query result, returning
performanc e of this operation.
them as a sequence of sequences (e.g. a list of tuples).
Note that the cursor's arraysize attribute can affect the
An Error (or subclass) exception is raised if the previous
call to .execute*() did not produce any result set or no
call was issued yet.
It does say explicitly that .fetchone() should return None and .fetchmany() an empty list.
It's easy to change indeed, but maybe I'm just missing the point in PEP-249?
Personally, I favor [] as well, it does indeed make sense.
"SELECT * FROM test WHERE 1 = 0" does produce an empty result set, so the exception is not raised either.