Python 2.7.3 (default, Jan 4 2013, 14:06:23) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sqlalchemy >>> print sqlalchemy.__version__ 0.8.0b2
Below is the code I was able to use to reproduce a problem I was having. Here is the stack trace: Traceback (most recent call last): File "test.py", line 48, in <module> print session.query(AbstractConcreteAbstraction).all() File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1079, in query return self._query_cls(entities, self, **kwargs) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 115, in __init__ self._set_entities(entities) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 122, in _set_entities entity_wrapper(self, ent) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2949, in __init__ "expected - got '%r'" % (column, ) sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected - got '<class '__main__.AbstractConcreteAbstraction'>' The workaround I discovered while trying to reproduce is to simply instantiate a subclass... am I missing something? from sqlalchemy.engine import Engine from sqlalchemy import event from sqlalchemy import (Column, Integer, Unicode, DateTime, ForeignKey, Boolean, Numeric, Time) # Taken from http://docs.sqlalchemy.org/ru/latest/dialects/sqlite.html @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection, connection_record): cursor = dbapi_connection.cursor() cursor.execute("PRAGMA foreign_keys=ON") cursor.close() from sqlalchemy import create_engine from sqlalchemy.ext.declarative import (declarative_base, declared_attr, AbstractConcreteBase) from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///test.db') sqlite = declarative_base(bind=engine) get_session = sessionmaker(bind=engine) session = get_session() from sqlalchemy.schema import UniqueConstraint class AbstractConcreteAbstraction(AbstractConcreteBase, sqlite): __table_args__ = (UniqueConstraint('derpa', 'derp'),) id = Column(Integer, primary_key=True) derpa = Column(Integer) derp = Column(Integer) class ConcreteConcreteAbstraction(AbstractConcreteAbstraction): __tablename__ = u'cca' __mapper_args__ = {'polymorphic_identity': 'ccb', 'concrete': True} print AbstractConcreteAbstraction sqlite.metadata.create_all() # DOES NOT WORK WITHOUT!!! # ConcreteConcreteAbstraction(derpa=2, derp=2) print session.query(AbstractConcreteAbstraction).all() print session.query(ConcreteConcreteAbstraction).all() -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.