Bug #77779 Example for version check for CAPI doesn't work
Submitted: 19 Jul 2015 8:16 Modified: 24 Jul 2015 12:52
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Documentation Severity:S3 (Non-critical)
Version:2.0.4, 2.1.2b1 OS:Any
Assigned to: CPU Architecture:Any

[19 Jul 2015 8:16] Daniël van Eeden
Description:
Page: http://dev.mysql.com/doc/connector-python/en/connector-python-cext-development.html

----------------------------
The following example illustrates one way to add use_pure to the connection arguments:

import mysql.connector

if mysql.connector.VERSION > (2, 1) and mysql.connector.HAVE_CEXT:
  config['use_pure'] = False
----------------------------

How to repeat:
Python 2.7.10 (default, May 27 2015, 18:11:38) 
[GCC 5.1.1 20150422 (Red Hat 5.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> mysql.connector.VERSION > (2, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VERSION'
>>> mysql.connector.__version_info__ > (2, 1)
False
>>> mysql.connector.__version__
'1.1.6'

Python 3.4.2 (default, Jan 12 2015, 12:13:20) 
[GCC 4.9.2 20150107 (Red Hat 4.9.2-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> mysql.connector.VERSION > (2, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VERSION'
>>> mysql.connector.__version_info__ > (2, 1)
False
>>> mysql.connector.__version__
'2.0.4'

Suggested fix:
replace mysql.connector.VERSION with mysql.connector.__version_info__
[20 Jul 2015 6:00] MySQL Verification Team
Hello Daniël,

Thank you for the report.

Thanks,
Umesh
[20 Jul 2015 6:01] MySQL Verification Team
//

[root@cluster-repo ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 01:49:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import mysql.connector
>>> mysql.connector.VERSION > (2, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VERSION'
>>> mysql.connector.__version_info__ > (2, 1)
True
>>> mysql.connector.__version__
'2.1.2b1'
>>>
[24 Jul 2015 12:52] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly.

Should be __version_info__, not VERSION:

if mysql.connector.__version_info__ > (2, 1) and mysql.connector.HAVE_CEXT:
  config['use_pure'] = False

VERSION can be used if you import mysql.connector.version, but let's keep the example simpler.