From eae9d1420bbfde4dbd835b654e80653cd5ac2155 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 25 Oct 2022 10:22:14 -0400 Subject: raise for non-Load opt passed to options() 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. Fixes: #8711 Change-Id: Iaa7b13956b808761e618a6be6406e5c82df1c65c --- lib/sqlalchemy/orm/strategy_options.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 114030346..23b3466f5 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -1218,7 +1218,16 @@ class Load(_AbstractLoad): """ for opt in opts: - opt._apply_to_parent(self) + try: + opt._apply_to_parent(self) + except AttributeError as ae: + if not isinstance(opt, _AbstractLoad): + raise sa_exc.ArgumentError( + f"Loader option {opt} is not compatible with the " + "Load.options() method." + ) from ae + else: + raise return self def _clone_for_bind_strategy( -- cgit v1.2.1