Skip to content

Don't crash when inspecting unsafe properties#454

Closed
AdamNiederer wants to merge 2 commits intopallets-eco:masterfrom
AdamNiederer:unsafe-properties
Closed

Don't crash when inspecting unsafe properties#454
AdamNiederer wants to merge 2 commits intopallets-eco:masterfrom
AdamNiederer:unsafe-properties

Conversation

@AdamNiederer
Copy link

If a class property is programmatically computed, it could potentially
throw an exception when run in this context. In that case, just move
on to the next property instead of crashing the entire application.

If a class property is programmatically computed, it could potentially
throw an exception when run in this context. In that case, just move
on to the next property instead of crashing the entire application.
@davidism davidism modified the milestone: v2.2 Jan 15, 2017

for name in dir(base):
attr = getattr(base, name)
attr = getattr(base, name, None)

Choose a reason for hiding this comment

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

where is the unittest that demonstrates that this helps

as far as i understood getattr will still fail in basically all computing exceptions (and rightfully so)

Copy link
Author

Choose a reason for hiding this comment

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

I came across this when Flask-SQLAlchemy was accessing a class property reliant on the name of the subclass in an abstract superclass as the superclass.

This fix catches AttributeErrors that may arise from Flask-SQLAlchemy's handling of abstract mixins, but would never be thrown in the program at runtime. We could change the way it handles abstract superclasses, but this fix is six characters and I can't think of any other problems which might arise from its current behavior.

@davidism davidism closed this in f4662ad Feb 27, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments