Problem with inheriting String (and Unicode) column types

Issue #944 resolved
Former user created an issue

The following code exposes the problem:

from sqlalchemy import *

meta = MetaData()
meta.bind = create_engine('sqlite:///:memory:')

class MultiLine(Unicode):
    pass

post = Table('post', meta,
            Column('comment', MultiLine)
        )

meta.create_all()

If you just use Unicode everything is OK --- a TEXT column is created. If you use a type that inherits String/Unicode, a VARCHAR(None) column is "created".

The fix is easy --- I have attached a patch: Index: lib/sqlalchemy/types.py =================================================================== --- lib/sqlalchemy/types.py (revision 4072) +++ lib/sqlalchemy/types.py (working copy) @@ -406,7 +406,7 @@ # if we are String or Unicode with no length, # return Text as the highest-priority type # to be adapted by the dialect - if self.length is None and l0 in (String, Unicode): + if self.length is None and isinstance(self, String): return (Text,) + l else: return l

Comments (2)

  1. Mike Bayer repo owner

    the "automatic" graduation of a length-less String to Text is deprecated. Subclass UnicodeText instead.

  2. Mike Bayer repo owner

    yeah....sorry, the patch breaks expected behavior too:

    >>> from sqlalchemy import * 
    >>> from sqlalchemy.databases.oracle import OracleDialect  
    >>> print VARCHAR().dialect_impl(OracleDialect()).get_col_spec()
    CLOB
    

    your test works fine if you subclass UnicodeText.

  3. Log in to comment