Skip to content

Do not propagate property getter errors from GetPropertiesImpl - #2211

Open
romangolev wants to merge 1 commit into
IronLanguages:mainfrom
pyrevitlabs:fix/customtypedesc-getter-errors
Open

romangolev wants to merge 1 commit into
IronLanguages:mainfrom
pyrevitlabs:fix/customtypedesc-getter-errors

Conversation

@romangolev

Copy link
Copy Markdown

CustomTypeDescHelpers.GetPropertiesImpl reads every attribute of a Python object to learn its type. A getter that raises made TypeDescriptor.GetProperties throw, which fails WPF binding resolution (Window.Show()) for a data context that has such a property.

A property whose getter raises is now typed object. Other types are unchanged, and SystemExit, KeyboardInterrupt and fatal exceptions still propagate. Attributes excluded by the attribute filters are no longer read. Tests are in CustomTypeDescriptorTest.cs; three fail without the change. Tested locally on net8.0.

A getter that raises made TypeDescriptor.GetProperties fail, which broke WPF bindings. Such a property is now typed as object.
@romangolev

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="pyrevitlabs"

@romangolev
romangolev marked this pull request as ready for review December 5, 2026 13:40
try {
object attrVal = ObjectOps.__getattribute__(DefaultContext.DefaultCLS, self, name);
return (attrVal == null) ? typeof(NoneTypeOps) : attrVal.GetType();
} catch (Exception ex) when (!(ex is OutOfMemoryException || ex is System.Threading.ThreadAbortException || ex is IronPython.Runtime.Exceptions.SystemExitException || ex is Microsoft.Scripting.KeyboardInterruptException)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these specific exceptions? If the goal is to just catch normal Python exceptions then something like this might be a better fit:

} catch (Exception ex) when (PythonOps.IsInstance(PythonExceptions.ToPython(ex), PythonExceptions.Exception)) {
    return typeof(object);
}

using NUnit.Framework;

namespace IronPythonTest {
public class CustomTypeDescriptorTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner to put these tests alongside the existing type descriptor tests in test_cliclass. Perhaps a new method (e.g. test_type_descs_getter_raises) next to test_type_descs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants