I'm upgrading a Pylons app from SQLAlchemy 0.3 to 0.4. One table is defined as:
incidents = Table("IN_Incident", meta,
Column("orr_id", Integer, primary_key=True),
autoload=True, autoload_with=engine)
The table is a MySQL VIEW that contains a column 'is_top'. The
application fails because the incidents.columns.is_top attribute does
not exist. Inspecting incident.columns in the Pylons debugger shows it
contains only the explicitly-defined column, not the autoloaded
columns:
>>> list(model.incidents.columns)
[Column('orr_id', Integer(), primary_key=True, nullable=False)]
In SQLAlchemy 0.3 it contained the autoloaded columns too. Was this
an intentional change or did the autoloading fail somehow? Without
the column attributes, I can't use the columns in a where expression.
Loading the table interactively produces the same problem:
$ python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy import *
>>> import sqlalchemy
>>> sqlalchemy
<module 'sqlalchemy' from
'/usr/local/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/__init__.pyc'>
>>> engine = create_engine("mysql://...", echo=True)
>>> meta = MetaData()
>>> incidents = Table("IN_Incident", meta,
... Column("orr_id", Integer, primary_key=True),
... autoload=True, autoload_with=engine)
2007-08-23 14:41:41,907 INFO sqlalchemy.engine.base.Engine.0x..4c SHOW
VARIABLES LIKE 'character_set%%'
2007-08-23 14:41:41,907 INFO sqlalchemy.engine.base.Engine.0x..4c None
2007-08-23 14:41:41,909 INFO sqlalchemy.engine.base.Engine.0x..4c SHOW
VARIABLES LIKE 'lower_case_table_names'
2007-08-23 14:41:41,909 INFO sqlalchemy.engine.base.Engine.0x..4c None
2007-08-23 14:41:41,909 INFO sqlalchemy.engine.base.Engine.0x..4c SHOW
CREATE TABLE `IN_Incident`
2007-08-23 14:41:41,910 INFO sqlalchemy.engine.base.Engine.0x..4c None
>>> list(incidents.columns)
[Column('orr_id', Integer(), primary_key=True, nullable=False)]
>>> incidents.columns.orr_id
Column('orr_id', Integer(), primary_key=True, nullable=False)
>>> incidents.columns.is_top
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/util.py",
line 281, in __getattr__
raise AttributeError(key)
AttributeError: is_top
>>> incidents.columns.name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/util.py",
line 281, in __getattr__
raise AttributeError(key)
AttributeError: name
>>>
The first time I tried this interactively I got another strange error,
but I can't reproduce it. This was with beta3:
$ python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy as sa
>>> engine = sa.create_engine("mysql://...", echo=True)
>>> meta = MetaData()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'MetaData' is not defined
>>> meta = sa.MetaData()
>>> incidents = Table("IN_Incident", meta,
... Column("orr_id", Integer, primary_key=True),
... autoload=True, autoload_with=engine)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Table' is not defined
>>> from sqlalchemy import *
>>> incidents = Table("IN_Incident", meta,
... Column("orr_id", Integer, primary_key=True),
... autoload=True, autoload_with=engine)
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File
"/usr/local/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta3-py2.5.egg/sqlalchemy/schema.py",
line 115, in __call__
autoload_with.reflecttable(table, include_columns=include_columns)
AttributeError: 'module' object has no attribute 'reflecttable'
>>>
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---