--- /dev/null
+.. change::
+ :tags: bug, orm, regression
+ :tickets: 6203
+
+ Fixed regression where a deprecated form of :meth:`_orm.Query.join` were
+ used, passing a series of entities to join from without any ON clause in a
+ single :meth:`_orm.Query.join` call, would fail to function correctly.
import operator
import types
-from sqlalchemy.sql import visitors
from . import exc as orm_exc
from . import interfaces
from . import loading
from .. import sql
from .. import util
from ..sql import coercions
+from ..sql import elements
from ..sql import expression
from ..sql import roles
from ..sql import Select
from ..sql import util as sql_util
+from ..sql import visitors
from ..sql.annotation import SupportsCloneAnnotations
from ..sql.base import _entity_namespace_key
from ..sql.base import _generative
(Item, Item.order_id == Order.id)
)
+ session.query(User).join(Order, Item)
+
# ... and several more forms actually
**Why it's legacy**: being able to chain multiple ON clauses in one
if not legacy and onclause is None and not isinstance(target, tuple):
# non legacy argument form
_props = [(target,)]
- elif not legacy and isinstance(
- target,
- (expression.Selectable, type, AliasedClass, types.FunctionType),
+ elif (
+ not legacy
+ and isinstance(
+ target,
+ (
+ expression.Selectable,
+ type,
+ AliasedClass,
+ types.FunctionType,
+ ),
+ )
+ and isinstance(
+ onclause,
+ (
+ elements.ColumnElement,
+ str,
+ interfaces.PropComparator,
+ types.FunctionType,
+ ),
+ )
):
# non legacy argument form
_props = [(target, onclause)]
"addresses.user_id JOIN users ON users.id = addresses.user_id",
)
+ def test_multiple_entities(self):
+ User = self.classes.User
+ Address = self.classes.Address
+ Dingaling = self.classes.Dingaling
+
+ s = fixture_session()
+
+ u1 = aliased(User)
+
+ with testing.expect_deprecated_20(join_chain_dep):
+ q1 = s.query(u1).join(Address, User)
+
+ self.assert_compile(
+ q1,
+ "SELECT users_1.id AS users_1_id, users_1.name AS users_1_name "
+ "FROM users AS users_1 JOIN addresses ON users_1.id = "
+ "addresses.user_id JOIN users ON users.id = addresses.user_id",
+ )
+
+ with testing.expect_deprecated_20(join_chain_dep):
+ q1 = s.query(u1).join(Address, User, Dingaling)
+
+ self.assert_compile(
+ q1,
+ "SELECT users_1.id AS users_1_id, users_1.name AS users_1_name "
+ "FROM users AS users_1 JOIN addresses "
+ "ON users_1.id = addresses.user_id "
+ "JOIN users ON users.id = addresses.user_id "
+ "JOIN dingalings ON addresses.id = dingalings.address_id",
+ )
+
def test_str_join_target(self):
User = self.classes.User