GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dlr branch fix - Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy by greateggsgreg · Pull Request #2718 · pythonnet/pythonnet

Conversation

@greateggsgreg

@greateggsgreg greateggsgreg commented May 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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_proxy swallowed exceptions raised from TryGetMember and returned default to Python while the prior AttributeError from PyObject_GenericGetAttr was still set. Callers therefore observed a misleading AttributeError instead 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 than Exceptions.SetError(e) deliberately. Wrapping the CLR exception object via Converter.ToPython triggers CLR type initialisation, which can re-enter tp_getattro_dlr_proxy on the same live dynamic object and recurse infinitely. A plain RuntimeError with the message string preserves the diagnostic information without that hazard.

Test

Adds ThrowingGetDynamicObject to dlrtest.cs and test_trygetmember_exception_is_raised_in_python to tests/test_dynamic.py, mirroring the existing coverage for TrySetMember/TryDeleteMember exception paths.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@greateggsgreg
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy
5d64310
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.
@greateggsgreg
greateggsgreg force-pushed the dlr branch from 5c3421f to 5d64310 Compare May 9, 2026 20:20
@greateggsgreg greateggsgreg changed the title Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy dlr branch fix - Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy May 9, 2026
@greateggsgreg greateggsgreg mentioned this pull request May 10, 2026
Implement support for DLR get/set #2706
Merged
@filmor
filmor merged commit da48ef7 into pythonnet:dlr May 11, 2026
27 of 29 checks passed

Uh oh!

There was an error while loading. Please reload this page.

filmor pushed a commit that referenced this pull request May 12, 2026
@greateggsgreg @filmor
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
93c8e38
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
@greateggsgreg @filmor
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
789726c
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
@greateggsgreg @filmor
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
a2ed667
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 15, 2026
@greateggsgreg @filmor
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
8b12b56
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.
@Martin-Molinero Martin-Molinero mentioned this pull request Jun 19, 2026
Add DLR get/set support (IDynamicMetaObjectProvider) QuantConnect/pythonnet#123
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@greateggsgreg @filmor
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.