.. include:: changelog_07.rst
:start-line: 5
+.. changelog::
+ :version: 1.0.3
+
+ .. change::
+ :tags: bug, orm
+ :tickets: 3387
+
+ Fixed issue in new :meth:`.QueryEvents.before_compile` event where
+ changes made to the :class:`.Query` object's collection of entities
+ to load within the event would render in the SQL, but would not
+ be reflected during the loading process.
+
.. changelog::
:version: 1.0.2
:released: April 24, 2015
ORDER BY or GROUP BY on a simple label name at all; when in fact,
we had forgotten that 0.9 was already emitting ORDER BY on a simple
label name for all backends, as described in :ref:`migration_1068`,
- even though 1.0 includes a rewrite of this logic as part of
+ even though 1.0 includes a rewrite of this logic as part of
:ticket:`2992`. As far
as emitting GROUP BY against a simple label, even Postgresql has
- cases where it will raise an error even though the label to group
+ cases where it will raise an error even though the label to group
on should be apparent, so it is clear that GROUP BY should never
be rendered in this way automatically.
- In 1.0.2, SQL Server, Firebird and others will again emit ORDER BY on
+ In 1.0.2, SQL Server, Firebird and others will again emit ORDER BY on
a simple label name when passed a
:class:`.Label` construct that is also present in the columns clause.
Additionally, no backend will emit GROUP BY against the simple label
close_with_result=True)
result = conn.execute(querycontext.statement, self._params)
- return loading.instances(self, result, querycontext)
+ return loading.instances(querycontext.query, result, querycontext)
@property
def column_descriptions(self):
class QueryEventsTest(
_RemoveListeners, _fixtures.FixtureTest, AssertsCompiledSQL):
- run_inserts = None
__dialect__ = 'default'
@classmethod
checkparams={'id_2': 10, 'id_1': 7}
)
+ def test_alters_entities(self):
+ User = self.classes.User
+
+ @event.listens_for(query.Query, "before_compile", retval=True)
+ def fn(query):
+ return query.add_columns(User.name)
+
+ s = Session()
+
+ q = s.query(User.id, ).filter_by(id=7)
+ self.assert_compile(
+ q,
+ "SELECT users.id AS users_id, users.name AS users_name "
+ "FROM users "
+ "WHERE users.id = :id_1",
+ checkparams={'id_1': 7}
+ )
+ eq_(
+ q.all(),
+ [(7, 'jack')]
+ )
+