- attached test.py
add explicit error when 'metadata' is used as a column name
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())
Output:
$ ./test.py
Traceback (most recent call last):
File "./test.py", line 24, in <module>
class SomeClass(SqlaBaseClass):
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/ext/declarative.py", 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/declarative.py", line 1058, in _as_declarative
**table_kw)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/schema.py", line 195, in __new__
if key in metadata.tables:
AttributeError: 'Column' object has no attribute 'tables'
Comments (5)
-
Account Deleted -
repo owner - changed milestone to 0.6.7
- changed title to add explicit error when 'metadata' is used as a column name
- marked as enhancement
mmmm, no .metadata is a reserved identifier on the declarative base. this is described at http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#accessing-the-metadata. will add an error message that is more descriptive.
-
Account Deleted 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?
-
repo owner - changed status to resolved
de9ec22de972ec66f07db8b745108c6248bec6ad b699528ae5c52eace413c7f6c6ab1de831fcea31
Yes I was going to mention, someday we might consider renaming this attribute to be
__metadata__
like the others, the rationale formetadata
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 usingcls.__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. -
repo owner - removed milestone
Removing milestone: 0.6.7 (automated comment)
- Log in to comment
test case