Skip to content

Commit

Permalink
Fix issue with model class passed to Resource constructor crashing on…
Browse files Browse the repository at this point in the history
… export (#1745)
  • Loading branch information
matthewhegarty committed Jan 23, 2024
1 parent eabba74 commit 5e76e6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docs/changelog.rst
Expand Up @@ -6,14 +6,13 @@ Changelog

- Pass :meth:`~import_export.mixins.BaseExportMixin.get_export_resource_kwargs` to Resource constructor
:meth:`~import_export.admin.ExportMixin.export_action` (#1739)

- Fix issue with model class passed to Resource constructor crashing on export (#1745)

3.3.6 (2024-01-10)
------------------

- Fix issue with highlight when using 'light' color scheme (#1728)


3.3.5 (2023-12-19)
------------------

Expand Down
2 changes: 1 addition & 1 deletion import_export/admin.py
Expand Up @@ -856,7 +856,7 @@ def export_action(self, request, *args, **kwargs):
[
field.column_name
for field in res(
model=self.model, **self.get_export_resource_kwargs(request)
**self.get_export_resource_kwargs(request)
).get_user_visible_fields()
],
)
Expand Down
20 changes: 19 additions & 1 deletion tests/core/tests/test_admin_integration.py
Expand Up @@ -8,7 +8,13 @@
import chardet
import django
import tablib
from core.admin import AuthorAdmin, BookAdmin, CustomBookAdmin, ImportMixin
from core.admin import (
AuthorAdmin,
BookAdmin,
BookResource,
CustomBookAdmin,
ImportMixin,
)
from core.models import Author, Book, Category, EBook, Parent
from django.contrib.admin.models import DELETION, LogEntry
from django.contrib.admin.sites import AdminSite
Expand Down Expand Up @@ -685,6 +691,18 @@ def test_export_passes_export_resource_kwargs(
self.assertEqual(response.status_code, 200)
self.assertEqual(2, mock_get_export_resource_kwargs.call_count)

def book_resource_init(self):
# stub call to the resource constructor
pass

@mock.patch.object(BookResource, "__init__", book_resource_init)
def test_export_passes_no_resource_constructor_params(self):
# issue 1716
# assert that the export call with a no-arg constructor
# does not crash
response = self.client.get("/admin/core/book/export/")
self.assertEqual(response.status_code, 200)

def test_export(self):
response = self.client.get("/admin/core/book/export/")
self.assertEqual(response.status_code, 200)
Expand Down

0 comments on commit 5e76e6c

Please sign in to comment.