On Aug 10, 2011, at 7:02 AM, Dirk Makowski wrote:

> Hi all,
> 
> from a given class I'd like to determine which attributes are columns, not 
> only physical columns present in the underlying table, but also those from a 
> relationship(). The FAQ seems to provide an answer ("What's the best way to 
> figure out which attributes are columns, given a class"), but the proposed 
> solution throws an "sqlalchemy.orm.exc.UnmappedClassError: Class 
> '<pym.models.usrmgr.Principal object at 0x3a69c10>' is not mapped" error in 
> my setup.

> 
> I'm using 0.7.2. with declarative classes, e.g.
> 
> DbBase = declarative_base()
> 
> class Principal(DbBase, PymMixin):
>     __tablename__ = "principal"
>     __table_args__ = {'schema': 'pym'}
>     is_enabled      = Column(Boolean, nullable=False, default=False)
>     ...
> 
> Does is matter that I try to read the attributes from a query?
> 
> qry = sess.query(Principal)
> for p in qry:
>     print p.display_name
> # Determine columns in last looped entity
> mapper = class_mapper(p)       #<---- this throws UnmappedClassError

"p" here is an instance of a Principal, i.e. "p = Principal(x, y, z..)", not a 
Principal class.   You'd say either class_mapper(type(p)), or object_mapper(p).

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to