dlr branch fix - Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy#2718
Merged
Conversation
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (pythonnet#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
filmor
pushed a commit
that referenced
this pull request
May 12, 2026
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
filmor
pushed a commit
that referenced
this pull request
May 12, 2026
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
filmor
pushed a commit
that referenced
this pull request
May 13, 2026
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the symmetric exception-propagation fix to the DLR getter, completing the fix called out by @lostmsu in the #2706 review.
Problem
tp_getattro_dlr_proxyswallowed exceptions raised fromTryGetMemberand returneddefaultto Python while the priorAttributeErrorfromPyObject_GenericGetAttrwas still set. Callers therefore observed a misleadingAttributeErrorinstead of the real failure — exactly the kind of silent error-masking the reviewer flagged for the setter (which was fixed in d629b87).Fix
Set a Python exception in the catch block before returning
default.We use
Exceptions.SetError(Exceptions.RuntimeError, e.Message)rather thanExceptions.SetError(e)deliberately. Wrapping the CLR exception object viaConverter.ToPythontriggers CLR type initialisation, which can re-entertp_getattro_dlr_proxyon the same live dynamic object and recurse infinitely. A plainRuntimeErrorwith the message string preserves the diagnostic information without that hazard.Test
Adds
ThrowingGetDynamicObjecttodlrtest.csandtest_trygetmember_exception_is_raised_in_pythontotests/test_dynamic.py, mirroring the existing coverage forTrySetMember/TryDeleteMemberexception paths.