mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-28 11:35:19 -04:00
- Fixed bug where use of the :meth:.Query.select_from method would
cause a subsequent call to the :meth:`.Query.with_parent` method to fail. fixes #3606 - add mark-as-fail test for #3607
This commit is contained in:
Vendored
+12
@@ -15,6 +15,18 @@
|
||||
.. include:: changelog_07.rst
|
||||
:start-line: 5
|
||||
|
||||
.. changelog::
|
||||
:version: 1.0.11
|
||||
|
||||
.. change::
|
||||
:tags: bug, orm
|
||||
:tickets: 3606
|
||||
:versions: 1.1.0b1
|
||||
|
||||
Fixed bug where use of the :meth:`.Query.select_from` method would
|
||||
cause a subsequent call to the :meth:`.Query.with_parent` method to
|
||||
fail.
|
||||
|
||||
.. changelog::
|
||||
:version: 1.0.10
|
||||
:released: December 11, 2015
|
||||
|
||||
@@ -289,6 +289,8 @@ class Query(object):
|
||||
return self._entities[0]
|
||||
|
||||
def _mapper_zero(self):
|
||||
# TODO: self._select_from_entity is not a mapper
|
||||
# so this method is misnamed
|
||||
return self._select_from_entity \
|
||||
if self._select_from_entity is not None \
|
||||
else self._entity_zero().entity_zero
|
||||
@@ -942,11 +944,13 @@ class Query(object):
|
||||
"""
|
||||
|
||||
if property is None:
|
||||
mapper_zero = inspect(self._mapper_zero()).mapper
|
||||
|
||||
mapper = object_mapper(instance)
|
||||
|
||||
for prop in mapper.iterate_properties:
|
||||
if isinstance(prop, properties.RelationshipProperty) and \
|
||||
prop.mapper is self._mapper_zero():
|
||||
prop.mapper is mapper_zero:
|
||||
property = prop
|
||||
break
|
||||
else:
|
||||
|
||||
@@ -398,8 +398,8 @@ def closed():
|
||||
return skip_if(BooleanPredicate(True, "marked as skip"))
|
||||
|
||||
|
||||
def fails():
|
||||
return fails_if(BooleanPredicate(True, "expected to fail"))
|
||||
def fails(reason=None):
|
||||
return fails_if(BooleanPredicate(True, reason or "expected to fail"))
|
||||
|
||||
|
||||
@decorator
|
||||
|
||||
@@ -3216,6 +3216,39 @@ class ParentTest(QueryTest, AssertsCompiledSQL):
|
||||
# sess.query(Order).with_parent(None, property='addresses').all()
|
||||
# == [Order(description="order 5")]
|
||||
|
||||
def test_select_from(self):
|
||||
User, Address = self.classes.User, self.classes.Address
|
||||
|
||||
sess = create_session()
|
||||
u1 = sess.query(User).get(7)
|
||||
q = sess.query(Address).select_from(Address).with_parent(u1)
|
||||
self.assert_compile(
|
||||
q,
|
||||
"SELECT addresses.id AS addresses_id, "
|
||||
"addresses.user_id AS addresses_user_id, "
|
||||
"addresses.email_address AS addresses_email_address "
|
||||
"FROM addresses WHERE :param_1 = addresses.user_id",
|
||||
{'param_1': 7}
|
||||
)
|
||||
|
||||
@testing.fails("issue #3607")
|
||||
def test_select_from_alias(self):
|
||||
User, Address = self.classes.User, self.classes.Address
|
||||
|
||||
sess = create_session()
|
||||
u1 = sess.query(User).get(7)
|
||||
a1 = aliased(Address)
|
||||
q = sess.query(a1).with_parent(u1)
|
||||
self.assert_compile(
|
||||
q,
|
||||
"SELECT addresses_1.id AS addresses_1_id, "
|
||||
"addresses_1.user_id AS addresses_1_user_id, "
|
||||
"addresses_1.email_address AS addresses_1_email_address "
|
||||
"FROM addresses AS addresses_1 "
|
||||
"WHERE :param_1 = addresses_1.user_id",
|
||||
{'param_1': 7}
|
||||
)
|
||||
|
||||
def test_noparent(self):
|
||||
Item, User = self.classes.Item, self.classes.User
|
||||
|
||||
|
||||
Reference in New Issue
Block a user