Test made on 0.4.0beta5. I tried to reflect the table from
some well known application (bugzilla bugs table)


>>> from sqlalchemy import *
>>>
>>> db = create_engine('mysql://%s:[EMAIL PROTECTED]/bugs' % (username, 
>>> password)  )
>>> metadata = MetaData(bind = db)
>>> bugs = Table('bugs', metadata, autoload = True)
/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.0beta5-py2.4.egg/sqlalchemy/databases/mysql.py:1971:
 RuntimeWarning: Incomplete reflection of column definition   `resolution` 
enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME','MOVED')
 NOT NULL default '',
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 114, in __call__
  File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line 1172, in 
reflecttable
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/mysql.py", line 1588, 
in reflecttable
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/mysql.py", line 1926, 
in reflect
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/mysql.py", line 2012, 
in _add_column
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/mysql.py", line 1109, 
in __init__
ValueError: max() arg is an empty sequence


In case somebody does not have bugzilla handy ;-):

CREATE TABLE `bugs` (
  `bug_id` mediumint(9) NOT NULL auto_increment,
  `assigned_to` mediumint(9) NOT NULL default '0',
  `bug_severity` enum('blocker A','critical','major B','normal','minor 
C','trivial','enhancement high','enhancement medium','enhancement low') default 
NULL,
  `bug_status` 
enum('UNCONFIRMED','NEW','ASSIGNED','REOPENED','RESOLVED','VERIFIED','CLOSED','ANNOUNCEMENT')
 NOT NULL default 'UNCONFIRMED',
  `creation_ts` datetime NOT NULL default '0000-00-00 00:00:00',
  `delta_ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
CURRENT_TIMESTAMP,
  `short_desc` mediumtext NOT NULL,
  `op_sys` enum('All','WinNT','Win2000','Windows 2003','DUNIX 4.0','Tru64 
5.1','OpenVMS 7.1','OpenVMS 7.2','OpenVMS 7.3','RedHat Ent. 2.1','RedHat Ent. 
3','RedHat Ent. 4','AIX 5.1','Solaris 2.6','Solaris 10') default NULL,
  `priority` enum('Very High','High','Normal','Low','Very Low') NOT NULL 
default 'Very High',
  `rep_platform` enum('All','Intel','Alpha') default NULL,
  `reporter` mediumint(9) NOT NULL default '0',
  `version` varchar(64) NOT NULL default '',
  `resolution` 
enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME','MOVED')
 NOT NULL default '',
  `target_milestone` varchar(20) NOT NULL default '---',
  `qa_contact` mediumint(9) NOT NULL default '0',
  `status_whiteboard` mediumtext NOT NULL,
  `votes` mediumint(9) NOT NULL default '0',
  `keywords` mediumtext NOT NULL,
  `lastdiffed` datetime NOT NULL default '0000-00-00 00:00:00',
  `everconfirmed` tinyint(4) NOT NULL default '0',
  `reporter_accessible` tinyint(4) NOT NULL default '1',
  `cclist_accessible` tinyint(4) NOT NULL default '1',
  `bug_file_loc` text,
  `estimated_time` decimal(5,2) NOT NULL default '0.00',
  `remaining_time` decimal(5,2) NOT NULL default '0.00',
  `alias` varchar(20) default NULL,
  `product_id` smallint(6) NOT NULL default '0',
  `component_id` smallint(6) NOT NULL default '0',
  PRIMARY KEY  (`bug_id`),
  UNIQUE KEY `alias` (`alias`),
  KEY `assigned_to` (`assigned_to`),
  KEY `creation_ts` (`creation_ts`),
  KEY `delta_ts` (`delta_ts`),
  KEY `bug_severity` (`bug_severity`),
  KEY `bug_status` (`bug_status`),
  KEY `op_sys` (`op_sys`),
  KEY `priority` (`priority`),
  KEY `reporter` (`reporter`),
  KEY `version` (`version`),
  KEY `resolution` (`resolution`),
  KEY `target_milestone` (`target_milestone`),
  KEY `qa_contact` (`qa_contact`),
  KEY `votes` (`votes`),
  KEY `product_id` (`product_id`),
  KEY `component_id` (`component_id`),
  FULLTEXT KEY `short_desc` (`short_desc`)
) ENGINE=MyISAM AUTO_INCREMENT=24917 DEFAULT CHARSET=latin1;

Look in the debugger shows that the subroutine
mysql.py/MsEnum/__init__ fails as specified if enums parameter is
empty (what happened here). This looks like one bug, I suspect one can
define enum without any value. Sth like

   if strip_enums:
      length = max([len(v) for v in strip_enums])
   else:
      length = 0

should probably do.

Another question is why this param is empty. Error happens while the
column 'resolution' is handled, in which possible values set is not
empty. Even without digging into the code, it seems likely that allowing
empty string can be confusing (some other enums are taken correctly).

Indeed, deeper look shows that parse_column does not return arg value
for this column. Looking further one can see that _re_column fails to
match the line
 
 `resolution` 
enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME','MOVED')
 NOT NULL default '',

only _re_column_loose matches.

To summarize, there are two bugs in mysql reflection code:

a) MsEnum constructor fails if given empty enums due to unchecked
   use of the max function

b) _re_column regular expression fails to match if empty string ('')
   is given as one of the values (or maybe as first, I do not know,
   not studied this regexp enough ;-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to