Skip to content

Export functionality loses admin filter context when using admin actions #2097

@uunbound

Description

@uunbound

Describe the bug
When using the export functionality through admin actions (selecting multiple records and exporting), the export process loses all applied admin filters. This results in exports containing records that don't match the filtered changelist view, leading to data inconsistency and incorrect exports.

To Reproduce
Steps to reproduce the behavior:

  1. Go to any Django admin changelist that uses ExportActionMixin
  2. Apply filters to narrow down the results
  3. Select multiple records from the filtered results using checkboxes
  4. Choose "Export selected [model]" from the action dropdown
  5. See that the export form appears but the exported data ignores all applied filters
  6. Result: Export contains records that don't match the filtered view

Versions (please complete the following information):

  • Django Import Export: 4.0.0+ (issue introduced in v4.0.0)
  • Python 3.8+
  • Django 4.2+

Expected behavior
Exports should respect all applied admin filters and only export records that match the current filtered view, maintaining consistency between what users see in the changelist and what gets exported. This was the behavior in django-import-export versions prior to v4.0.0.

Additional context
The export form URL ("export_url" in the context) doesn't include the query parameters necessary for the export queryset to correctly narrow down the results. When the export form is submitted, it lacks the filter context (like ?date=2024-01-01&status=active) that was present in the original changelist view, causing the export to process the unfiltered dataset.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions