add explicit error when 'metadata' is used as a column name

Issue #2050 resolved
Anonymous created an issue

See attached minimal test case. Specifying a PickleType column using declarative_base results in an exception thrown on startup.

Sample code (full test case attached):

SqlaBaseClass = declarative_base()
class SomeClass(SqlaBaseClass):
    __tablename__ = 'results'
    rid         = Column(Integer, primary_key=True)
    metadata    = Column(PickleType())


$ ./
Traceback (most recent call last):
  File "./", line 24, in <module>
    class SomeClass(SqlaBaseClass):
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/ext/", line 1167, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/ext/", line 1058, in _as_declarative
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/", line 195, in __new__
    if key in metadata.tables:
AttributeError: 'Column' object has no attribute 'tables'

Comments (5)

  1. Anonymous

    Thanks for the quick reply -- I missed the obvious name clash even though I use the 'real' metadata (as per your link) :-/ Sorry about that.

    Side note for a potential future milestone: It might not be unreasonable to rename to metadata at some point, as with other 'special' variables like table, tablename, and tableargs. Or perhaps that notation is specific to variables that are meant to be overridden?

  2. Michael Bayer repo owner

    de9ec22de972ec66f07db8b745108c6248bec6ad b699528ae5c52eace413c7f6c6ab1de831fcea31

    Yes I was going to mention, someday we might consider renaming this attribute to be __metadata__ like the others, the rationale for metadata was that it would be more commonly accessed. I didn't think that the other __names__ names would be so widely used as accessors (i.e. people using cls.__table__, etc.) so if it were today, I'd have gone with __metadata__. We already have a huge list of changes for 0.7 (though mostly backwards compatible) but I don't know if I want to add another surprise on the heap just yet.

  3. Log in to comment