New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added guard for null 'options' to fix crash (#1163) #1325
added guard for null 'options' to fix crash (#1163) #1325
Conversation
@manelclos please could you cast your eye over this change - this would be the last one to go into 2.6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this change, as dir(options) will not return None even when options is None.
Removed the code modifications and the tests passes with no problems.
Tried other tests to understand when it fails and why, but they all pass:
@mock.patch("builtins.dir")
def test_new_handles_null_options(self, mock_dir):
# #1163 - simulates a call to dir() returning additional attributes
mock_dir.return_value = None
MyResource()
@mock.patch("builtins.dir")
def test_new_handles_null_options(self, mock_dir):
# #1163 - simulates a call to dir() returning additional attributes
mock_dir.return_value = []
MyResource()
Hi Manel, thanks for reviewing. The issue only occurs when the The test has to simulate returning values from
It will be fine unless you install |
Hi Matthew, I see. I spent some more time checking and found that you need a base class to trigger the code we want to test, something like this does the trick: @mock.patch("builtins.dir")
def test_new_handles_null_options(self, mock_dir):
# #1163 - simulates a call to dir() returning additional attributes
mock_dir.return_value = ['attrs']
class A(MyResource):
pass
A() Then, options is not Falsy, so the code needs to be changed to something like this: for option in [option for option in dir(options)
if not option.startswith('_') and hasattr(options, option)]: Once I made these changes it makes sense. Let me know what you think. |
387ed56
to
7a6ecb7
Compare
Looks good - thank you for those suggestions - I've added that in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Problem
If the forbiddenfruit library is installed, then crashes are seen at object instantiation.
The cause is that when forbiddenfruit is installed, calling
dir()
on a null object returns additional properties. The logic attempts to get these properties from a nulloptions
reference, which causes the crash:#1163
Solution
This fix adds a check that
options
is not None.Acceptance Criteria
forbiddenfruit
installed