From: Mike Bayer Date: Sun, 26 Apr 2015 16:33:17 +0000 (-0400) Subject: - Fixed issue in new :meth:`.QueryEvents.before_compile` event where X-Git-Tag: rel_1_0_3~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d48acff23bc04dafa958e76ef2ff614aa8d6751b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. fixes #3387 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 124ee22faf..5b410e74ff 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -15,6 +15,18 @@ .. 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 @@ -30,14 +42,14 @@ 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 diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 69ab887726..153b10a2bf 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -120,7 +120,7 @@ from .schema import ( from .inspection import inspect from .engine import create_engine, engine_from_config -__version__ = '1.0.2' +__version__ = '1.0.3' def __go(lcls): diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 2bd68899b9..c3638f66d4 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2528,7 +2528,7 @@ class Query(object): 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): diff --git a/test/orm/test_events.py b/test/orm/test_events.py index 179f914fc2..89cc54eb82 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -1886,7 +1886,6 @@ class SessionExtensionTest(_fixtures.FixtureTest): class QueryEventsTest( _RemoveListeners, _fixtures.FixtureTest, AssertsCompiledSQL): - run_inserts = None __dialect__ = 'default' @classmethod @@ -1917,3 +1916,25 @@ class QueryEventsTest( 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')] + ) +