_TextClause exception with text == 0

Issue #1842 resolved
Former user created an issue

Hello,

I am having an error on a big sqlite database (260MB). When trying to reflect it ( records = sqlalchemy.Table('transactions', metadata, autoload=True) ) I get an error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\schema.py", line 207, in new File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\schema.py", line 261, in _init File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\engine\base.py", line 1776, in reflecttable File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\engine\default.py", line 206, in reflecttable File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\engine\reflection.py", line 325, in reflecttable File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\sql\expression.py", line 820, in text File "c:\python25\lib\site-packages\sqlalchemy-0.6.1-py2.5.egg\sqlalchemy\sql\expression.py", line 2364, in init TypeError: expected string or buffer

By looking deeper, it appears text is the 0 integer ... The issue is solved if I do this (before line 2364, SA 0.6.1):

if text == 0: text = ''

... then it reflects correctly.

The strange part is that using the same database when it was much smaller it worked perfectly (didnt event go to the _TextClause code).

Hth ...

Comments (5)

  1. Mike Bayer repo owner

    Can't reproduce on this end:

    from sqlalchemy import *
    
    engine = create_engine('sqlite://', echo='debug')
    
    engine.execute("""
    CREATE TABLE t (foo INTEGER DEFAULT 0)
    """)
    
    m = MetaData()
    
    t = Table('t', m, autoload=True, autoload_with=engine)
    

    works fine, the "0" comes back as the string 0. Need to see the sqlite table construct which is producing this result.

  2. Former user Account Deleted

    This didnt happen when my table was almost empty, but after lot of data on it it returned me an integer as the text variable. I could print it's type and it was an int. I checked the db integrity and it was ok.

  3. Mike Bayer repo owner

    OK nothing can be done here until a complete and succinct test script is provided which reproduces the issue. As it stands it looks like a simple case of reflection, the data in the table should have nothing to do with the results of reflection unless there's some odd sqlite bug at play.

  4. Log in to comment