its most likely uncompiled mappers.  the "c" attribute on the class  
is deprecated; use Table.attribute instead.  Also issue  
compile_mappers() after your mappers have been established to force a  
compile.  The typical usage pattern is that the session.query() is  
created first, which also issues a mapper compile operation.



On Aug 29, 2007, at 3:21 AM, Marco De Felice wrote:

>
> With SA 0.4beta4 if I try to access a mapped object field
> (Table.c.fieldname) before any query  has been sent to the database  
> the
> call fails with a AttributeError(key). Everything works if I do this
> after having issued a query.
>
> -- Example: (skip to the __main__ section)
>
> import sqlalchemy as sqa
> import sqlalchemy.orm as sqorm
>
> class Table(object):
>     pass
>
> class Model(object):
>
>     def connect(self, u, p, db, h):
>
>         dsn =""postgres://%(u)s:%(p)[EMAIL PROTECTED](h)s:5432/%(db)s""" % 
> vars()
>
>         self.engine = sqa.create_engine(dsn)
>
>         metadata = sqa.MetaData()
>         metadata.bind = self.engine
>
>         self.table_table = sqa.Table('table', metadata,
>               sqa.Column('id', sqa.Integer,
>                        primary_key = True),
>               sqa.Column('field1', sqa.String(120))
>               )
>
>       sqorm.mapper(Table, self.table_table)
>
>
> if __name__ == "__main__":
>
>     model = Model()
>     model.connect("user", "password", "db", "host")
>
>     session = sqorm.create_session()
>
>     filters = []
>
>     #THE FOLLOWING WILL FAIL WITH AttributeError: field1
>     #BUT NOT IF A QUERY HAS ALREADY BEEN ISSUED
>     #also against another mapped object.
>     #test = session.query(ANYMAPPEDOBJ).all()
>     #test = session.query(Table).all()
>     #uncomment one of the above and it works
>
>     filters.append(Table.c.field1.op('ILIKE') ("FILTERTEXT"))
>
>     filter = sqa.and_(*filters)
>     result = session.query(Table).\
>                       filter(filter).\
>                       all()
>
>
>     session.close()
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to