Infinite recursion when setting connection client_flags

Bug #695514 reported by blep
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
MySQL Connector/Python
Status tracked in Trunk
0.3
Fix Released
Medium
Geert JM Vanderkelen
Trunk
In Progress
Medium
Geert JM Vanderkelen

Bug Description

* How to reproduce:
import mysql.connector
mysql.connector.connect( client_flags=mysql.connector.ClientFlag.FOUND_ROWS )
[...]
  File "C:\Python31\lib\site-packages\mysql\connector\connection.py", line 601, in set_client_flags
    self.set_client_flags(flags)
  File "C:\Python31\lib\site-packages\mysql\connector\connection.py", line 601, in set_client_flags
    self.set_client_flags(flags)
  File "C:\Python31\lib\site-packages\mysql\connector\connection.py", line 600, in set_client_flags
    if isinstance(flags,int) and flags > 0:
RuntimeError: maximum recursion depth exceeded in cmp

* Cause:
    def set_client_flags(self, flags):
        if isinstance(flags,int) and flags > 0:
            self.set_client_flags(flags)
=> if an int is passed, an infinite recursion occurs my guess is that self.set_client_flag (without 's') should be called.

Environment info:

* MySQL Connector/Python version (and/or revision)
python -c "import mysql.connector as db; print( db.__version__ )"
(0, 3, 0, 'devel', 287)

* Python version
python --version
Python 3.1.1

mysql> SELECT VERSION()
| 5.0.51b-community-nt |

* Platform/OS: Windows XP SP2 32 bits

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

Yes, the RunTimeError is indeed a bug. It should have been self.client_flags = flags when an int is given.

It is, however, not recommended to use an int, but a list. From the docs (which we really need to push online one day..):

---

         MySQL uses client flags when connecting to enable or disable
         certain features. Using the *client_flags* arguments you have
         control of what is set. To find out what flags are available,
         you can use the following:

          >>> from mysql.connector.constants import ClientFlag
          >>> print '\n'.join(ClientFlag.get_full_info())

         If *client_flags* is not specified (that is, it is zero), defaults
         will used for MySQL v4.1 and later. If you specify an integer greater
         than ``0``, you need to make sure all flags are set. However, a much
         better way to set and unset flags is to use a list.

         For example, you want to set the FOUND_ROWS-flag:

         >>> mysql.connector.connect(client_flags=[ClientFlag.FOUND_ROWS])

         If you want to unset one of the defaults, e.g. LONG_FLAG:

         >>> mysql.connector.connect(client_flags=[
            ClientFlag.FOUND_ROWS,
            -ClientFlag.LONG_FLAG,
            ])

---

Thus, in this case, correct would be:

mysql.connector.connect( client_flags=[mysql.connector.ClientFlag.FOUND_ROWS] )

I found doing it using a sequence much more intuitive and clearer, what you think?

Changed in myconnpy:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Geert JM Vanderkelen (geertjmvdk)
milestone: none → 0.3.1
Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

But.. maybe you're right, and I should just keep the bitwise assignment as well as list..
Let me review this.

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) wrote :

If you give the client_flags as integer, it is set as is (this was not working before). No bitwise operations are done on the default flags.
It's much better to use a list of flags to set/unset.

Blogged about this here: http://geert.vanderkelen.org/post/488/

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.