mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-30 20:44:45 -04:00
- 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
This commit is contained in:
Vendored
+15
-3
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
+22
-1
@@ -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')]
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user