]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed issue in new :meth:`.QueryEvents.before_compile` event where
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Apr 2015 16:33:17 +0000 (12:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Apr 2015 16:33:17 +0000 (12:33 -0400)
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

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/orm/query.py
test/orm/test_events.py

index 124ee22fafe01e291363ceaf30e7885658e8cb16..5b410e74ff854a2283cd0d94407812571a5d52e2 100644 (file)
     .. 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
index 69ab887726cb1f7204901ca1d80f7d1e8d501776..153b10a2bfd49f33347a766110b24f636597e1db 100644 (file)
@@ -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):
index 2bd68899b94379308d2914c943407b701c9d83b9..c3638f66d46e7e160cf95e161a6299f5362e580a 100644 (file)
@@ -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):
index 179f914fc2b1428ab3ac185d5e66bfd1a447e7a6..89cc54eb82c909bbafa54d436cb416b618a1bc6d 100644 (file)
@@ -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')]
+        )
+