- changed milestone to 0.5.xx
- changed component to sql
- changed title to Support getting the engine from column expressions against scalar subqueries
Support getting the engine from column expressions against scalar subqueries
Issue #1326
resolved
(original reporter: ged) The attached test case fails with the following traceback:
Traceback (most recent call last):
File "test_getenginefromfunc.py", line 61, in <module>
print session.query(func.sum(User.score)).scalar()
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/query.py", line 1268, in scalar
ret = list(self)[0](0)
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/query.py", line 1280, in __iter__
return self._execute_and_instances(context)
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/query.py", line 1283, in _execute_and_instances
result = self.session.execute(querycontext.statement, params=self._params, mapper=self._mapper_zero_or_none())
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/session.py", line 752, in execute
engine = self.get_bind(mapper, clause=clause, **kw)
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/session.py", line 890, in get_bind
', '.join(context)))
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on SQL expression or this Session
Binding the session with the engine makes it work. IMHO, it shouldn't be needed since the tables that are selected from are within a metadata object which is already bound to it.
Comments (4)
-
repo owner -
repo owner - changed milestone to 1.x.xx
-
repo owner - changed milestone to 1.0
- edited description
will be fixed by
#3227 -
repo owner - changed status to resolved
- The primary :class:
.Mapper
of a :class:.Query
is now passed to the :meth:.Session.get_bind
method when calling upon :meth:.Query.count
, :meth:.Query.update
, :meth:.Query.delete
, as well as queries against mapped columns, :obj:.column_property
objects, and SQL functions and expressions derived from mapped columns. This allows sessions that rely upon either customized :meth:.Session.get_bind
schemes or "bound" metadata to work in all relevant cases. fixes#3227fixes#3242fixes#1326
→ <<cset 611883ffb35c>>
- Log in to comment
Replying to ged:
the key phrase here is "tables that are selected from". The statement has no FROM clause. The scalar subquery in its column expression does, but most constructs look to the immediate FROM clauses as the source of binds.