--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 8711
+
+ Fixed the exception that's raised when the
+ :func:`_orm.with_loader_criteria` option is attempted to be used within a
+ specific loader path, like in loader.options().
+ :func:`_orm.with_loader_criteria` is only intended to be used at the top
+ level.
"for 'unbound' loader options"
)
for opt in opts:
- opt._apply_to_parent(self, apply_cache, bound)
+ try:
+ opt._apply_to_parent(self, apply_cache, bound)
+ except AttributeError as ae:
+ if not isinstance(opt, Load):
+ util.raise_(
+ sa_exc.ArgumentError(
+ "Loader option %s is not compatible with the "
+ "Load.options() method." % (opt,)
+ ),
+ from_=ae,
+ )
+ else:
+ raise
@_generative
def set_relationship_strategy(
from sqlalchemy.orm import with_loader_criteria
from sqlalchemy.orm.decl_api import declared_attr
from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_raises_message
from sqlalchemy.testing.assertions import expect_raises
from sqlalchemy.testing.assertsql import CompiledSQL
from sqlalchemy.testing.fixtures import fixture_session
"FROM users WHERE users.name != :name_1",
)
+ def test_err_given_in_pathed(self, user_address_fixture):
+ User, Address = user_address_fixture
+
+ with expect_raises_message(
+ sa_exc.ArgumentError,
+ r"Loader option <.*LoaderCriteriaOption.*> is not compatible "
+ r"with the Load.options\(\) method.",
+ ):
+ select(User).options(
+ selectinload(User.addresses).options(
+ with_loader_criteria(
+ Address, Address.email_address != "foo"
+ )
+ )
+ )
+
def test_criteria_post_replace(self, user_address_fixture):
User, Address = user_address_fixture