Using MSBit type with sqlite causes "TypeError: argument 2 to map() must support iteration"

Issue #1404 resolved
Former user created an issue

I like to be able to use sqlite for unit tests, even though I use MySQL in production. Some of our columns are of type "MSBit". This seems to cause "TypeError: argument 2 to map() must support iteration" under certain circumstances.

I have attached a short script that should demonstrate the problem. If you uncomment this line and run it, it works fine:

#BIT = Boolean

But if you leave it commented-out (which means that BIT will get set to MSBit), you'll get:

Traceback (most recent call last): File "/home/jacob/Workspace/dev/Jacob/Crap/sabugrepro.py", line 39, in test_pkid joe = session.query(User).filter_by(name="Joe").one() File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/query.py", line 1247, in one ret = list(self0:2) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/query.py", line 1147, in getitem return list(res) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/query.py", line 1348, in instances rows = [process0(context, row) for row in fetch] File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/query.py", line 1946, in main return _instance(row, None) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/mapper.py", line 1640, in _instance populate_state(state, row, isnew, only_load_props) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/mapper.py", line 1530, in populate_state populator(state, row, isnew=isnew, **flags) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/orm/strategies.py", line 119, in new_execute state.dictkey = rowcol File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/engine/base.py", line 1348, in getitem return self.__parent._get_col(self.__row, key) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/engine/base.py", line 1620, in _get_col return processor(rowindex) File "/home/jacob/Workspace/kits/trunk/output/site-packages/SQLAlchemy-0.5.3-py2.6.egg/sqlalchemy/databases/mysql.py", line 682, in process for i in map(ord, value): TypeError: argument 2 to map() must support iteration


Comments (4)

  1. Former user Account Deleted

    Forgot to mention:

    I'm using SA 0.5.3 Python 2.6 Ubuntu 9.04

    Although I believe I was able to repro on Windows with SA 0.4.8 as well...

  2. Mike Bayer repo owner

    MSBit is specific to MySQL and the MySQLdb implementation of this type, and can't be expected to work with other dialects. You'll need to write your own type that works with SQLite, and then use a TypeDecorator:

    class SomeSQLiteType(TypeEngine):
        # ... implement a SQLite-compatible type
        # that behaves like you need MSBit to behave
    
    class BitType(TypeDecorator):
        impl = SomeSQLiteType
    
        def load_dialect_impl(self, dialect):
            if dialect.name == 'sqlite':
                return dialect.type_descriptor(SomeSQLiteType)
            else:
                return dialect.type_descriptor(MSBit())
    
  3. Former user Account Deleted

    Thanks for the feedback, that totally fixed things. Just for the record, the reason this was so confusing is that some of the other common MySQL types (such as MSString) work just fine on Sqlite, so I just assumed that they were all supposed to (or that there'd be some kind of obvious feedback indicating MSBit shouldn't be used with a non-MySQL database).

  4. Log in to comment