Skip to content

Commit

Permalink
Merge branch 'main' into drop-old-version-support
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhegarty committed Mar 31, 2022
2 parents 1664c50 + cdcfa9e commit 663af80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ The following is a list of much appreciated contributors:
* josx (José Luis Di Biase)
* Jan Rydzewski
* 2ykwang (Yeongkwang Yang)
* Mark Walker
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
- Updated import.css to support dark mode (#1318)
- Fix crash when import_data() called with empty Dataset and `collect_failed_rows=True` (#1381)
- Improve Korean translation (#1402)
- Update example subclass widget code (#1407)
- Drop support for python3.6, django 2.2, 3.0, 3.1 (#1408)

2.7.1 (2021-12-23)
Expand Down
2 changes: 1 addition & 1 deletion import_export/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def get_queryset(self, value, row, *args, **kwargs):
like so::
class FullNameForeignKeyWidget(ForeignKeyWidget):
def get_queryset(self, value, row):
def get_queryset(self, value, row, *args, **kwargs):
return self.model.objects.filter(
first_name__iexact=row["first_name"],
last_name__iexact=row["last_name"]
Expand Down
14 changes: 13 additions & 1 deletion tests/core/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_render_empty(self):

def test_clean_multi_column(self):
class BirthdayWidget(widgets.ForeignKeyWidget):
def get_queryset(self, value, row):
def get_queryset(self, value, row, *args, **kwargs):
return self.model.objects.filter(
birthday=row['birthday']
)
Expand All @@ -304,6 +304,18 @@ def get_queryset(self, value, row):
row = {'name': "Foo", 'birthday': author2.birthday}
self.assertEqual(birthday_widget.clean("Foo", row), author2)

def test_invalid_get_queryset(self):
class BirthdayWidget(widgets.ForeignKeyWidget):
def get_queryset(self, value, row):
return self.model.objects.filter(
birthday=row['birthday']
)

birthday_widget = BirthdayWidget(Author, 'name')
row = {'name': "Foo", 'age': 38}
with self.assertRaises(TypeError):
birthday_widget.clean("Foo", row, row_number=1)

def test_render_handles_value_error(self):
class TestObj(object):
@property
Expand Down

0 comments on commit 663af80

Please sign in to comment.