Cool, thanks!

On Mon, Feb 3, 2014 at 7:14 PM, Michael Bayer <[email protected]>wrote:

> just call configure_mappers() for now, and the need for that step has been
> removed in b069127b2d3f7b3f2c27f91cf,
> http://www.sqlalchemy.org/trac/ticket/2935.
>
>
> On Feb 3, 2014, at 4:12 PM, Matthew Phipps <[email protected]>
> wrote:
>
> Hi SQLAlchemy,
>
> On SQLAlchemy 0.9.2, if I construct a query selecting a composite property
> before constructing any other queries, I see this error:
>
> Traceback (most recent call last):
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/nose/case.py",
> line 197, in runTest
>     self.test(*self.arg)
>   File "/media/psf/vagrant/test_configure_mappers.py", line 47, in
> test_composite_prop_query
>     user_login_query = Session.query(User.login)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py",
> line 149, in do
>     return getattr(self.registry(), name)(*args, **kwargs)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py",
> line 1151, in query
>     return self._query_cls(entities, self, **kwargs)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
> line 106, in __init__
>     self._set_entities(entities)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
> line 114, in _set_entities
>     entity_wrapper(self, ent)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
> line 3338, in __init__
>     column = column._query_clause_element()
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py",
> line 150, in _query_clause_element
>     return self.comparator._query_clause_element()
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/descriptor_props.py",
> line 407, in _query_clause_element
>     return CompositeProperty.CompositeBundle(self.prop,
> self.__clause_element__())
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/descriptor_props.py",
> line 404, in __clause_element__
>     return expression.ClauseList(group=False, *self._comparable_elements)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py",
> line 689, in __get__
>     obj.__dict__[self.__name__] = result = self.fget(obj)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/descriptor_props.py",
> line 419, in _comparable_elements
>     return self.prop._comparable_elements
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py",
> line 689, in __get__
>     obj.__dict__[self.__name__] = result = self.fget(obj)
>   File
> "/home/badmin/.virtualenvs/bridge-it/local/lib/python2.7/site-packages/sqlalchemy/orm/descriptor_props.py",
> line 236, in _comparable_elements
>     for prop in self.props
> AttributeError: 'CompositeProperty' object has no attribute 'props'
>
> I've written a nose test module that exposes this behavior. Note that no
> SQL is ever actually issued (AFAIK?).
>
> import logging
>
> from sqlalchemy import create_engine, Column, Integer, String
> from sqlalchemy.orm import composite, sessionmaker, configure_mappers,
> scoped_session
> from sqlalchemy.ext.declarative import declarative_base
>
> engine = create_engine('sqlite:///:memory:')
> session_factory = sessionmaker(bind=engine)
> Session = scoped_session(session_factory)
> Base = declarative_base()
> logging.basicConfig()
> logging.getLogger('sqlalchemy.orm').setLevel(logging.INFO)
>
>
> class Login(object):
>
>     def __init__(self, name, password):
>         self.name = name
>         self.password = password
>
>     def __composite_values__(self):
>         return self.name, self.password
>
>
> class User(Base):
>     __tablename__ = 'users'
>
>     id = Column(Integer, primary_key=True)
>     name = Column(String)
>     fullname = Column(String)
>     password = Column(String)
>
>     login = composite(Login, name, password)
>
>     def __repr__(self):
>        return "<User(name='%s', fullname='%s', password='%s')>" % (
>                             self.name, self.fullname, self.password)
>
>
> class TestConfigureMappers(object):
>
>     def tearDown(self):
>         Session.remove()
>
>     # This fails
>     def test_composite_prop_query(self):
>         user_login_query = Session.query(User.login)
>
>     # This works
>     def test_composite_prop_query_configuring_first(self):
>
>         # Either of these two lines will suffice
>         user_query = Session.query(User)
>         #configure_mappers()
>
>         user_login_query = Session.query(User.login)
>         user_login = user_login_query
>
> Is this expected behavior? I figure that configure_mappers() must be
> exposed publicly for a reason, but the docs say querying should be good
> enough to invoke this process:
> http://docs.sqlalchemy.org/en/latest/changelog/migration_07.html?highlight=configure_mappers#compile-mappers-renamed-configure-mappers-simplified-configuration-internals.
>
> Thanks,
> Matt
>
> --
> 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 [email protected].
>
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to