summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-04-26 12:33:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-04-26 12:33:17 -0400
commitd48acff23bc04dafa958e76ef2ff614aa8d6751b (patch)
tree1fa123565e7dfd5b479c4a543b3ce3dcb7ccec47
parent6833669469b646fbd332b9ce4bd59a1122d3aa99 (diff)
downloadsqlalchemy-d48acff23bc04dafa958e76ef2ff614aa8d6751b.tar.gz
- 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
-rw-r--r--doc/build/changelog/changelog_10.rst18
-rw-r--r--lib/sqlalchemy/__init__.py2
-rw-r--r--lib/sqlalchemy/orm/query.py2
-rw-r--r--test/orm/test_events.py23
4 files changed, 39 insertions, 6 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 124ee22fa..5b410e74f 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -16,6 +16,18 @@
: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 69ab88772..153b10a2b 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 2bd68899b..c3638f66d 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 179f914fc..89cc54eb8 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')]
+ )
+