Skip to content

Commit

Permalink
added guard for null 'options' to fix crash (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhegarty committed Sep 1, 2021
1 parent 89e5240 commit 387ed56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions import_export/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __new__(cls, name, bases, attrs):
# Collect the Meta options
options = getattr(base, 'Meta', None)
for option in [option for option in dir(options)
if not option.startswith('_')]:
if options and not option.startswith('_')]:
setattr(meta, option, getattr(options, option))

# Add direct fields
Expand All @@ -198,7 +198,7 @@ def __new__(cls, name, bases, attrs):
# Add direct options
options = getattr(new_class, 'Meta', None)
for option in [option for option in dir(options)
if not option.startswith('_')]:
if options and not option.startswith('_')]:
setattr(meta, option, getattr(options, option))
new_class._meta = meta

Expand Down
6 changes: 6 additions & 0 deletions tests/core/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def test_meta(self):
self.assertIsInstance(self.my_resource._meta,
resources.ResourceOptions)

@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']
MyResource()

def test_get_export_order(self):
self.assertEqual(self.my_resource.get_export_headers(),
['email', 'name', 'extra'])
Expand Down

0 comments on commit 387ed56

Please sign in to comment.