From 764e36e5e7b7faf1a97b4b06be1ca307ac4fce46 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 18 Mar 2022 10:33:40 -0400 Subject: catch unexpected errors when accessing clslevel attribute Improved the error message that's raised for the case where the :func:`.association_proxy` construct attempts to access a target attribute at the class level, and this access fails. The particular use case here is when proxying to a hybrid attribute that does not include a working class-level implementation. Fixes: #7827 Change-Id: Ic6ff9df010f49253e664a1e7c7e16d8546006965 --- lib/sqlalchemy/ext/associationproxy.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sqlalchemy/ext') diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 4d2b1d8b6..194eabb64 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -583,6 +583,13 @@ class AssociationProxyInstance(SQLORMOperations[_T]): return AmbiguousAssociationProxyInstance( parent, owning_class, target_class, value_attr ) + except Exception as err: + raise exc.InvalidRequestError( + f"Association proxy received an unexpected error when " + f"trying to retreive attribute " + f'"{target_class.__name__}.{parent.value_attr}" from ' + f'class "{target_class.__name__}": {err}' + ) from err else: return cls._construct_for_assoc( target_assoc, parent, owning_class, target_class, value_attr -- cgit v1.2.1