From a2f310585ecd2f2f88b9b24498e1fb64320547e6 Mon Sep 17 00:00:00 2001 From: Mohammed Alkindi Date: Mon, 17 Aug 2026 11:52:34 +0400 Subject: [PATCH] fix(dbf): advertise dbf, not csv, as the file extension DBFFormat.extensions has read ('csv',) since the class-based format refactor in f1046cd, where it was copy-pasted from CSVFormat and never corrected. Nothing inside tablib reads .extensions, so the test suite never noticed, but the attribute is public format metadata that downstream consumers depend on. django-import-export is the concrete case: TablibFormat.get_extension() returns self.get_format().extensions[0], and get_export_filename() interpolates that into the filename the Django admin Export button serves. Measured against django-import-export 4.4.1 on Django 6.1, a DBF export downloaded as Invoice-2026-08-17.csv even though its leading bytes were a DBF header and tablib.detect_format correctly reported dbf. With this change the same export is named Invoice-2026-08-17.dbf. Adds a regression test to DBFTests. It is the first test in the suite to assert on a format's extensions attribute, so the mismatch cannot silently return. --- src/tablib/formats/_dbf.py | 2 +- tests/test_tablib.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tablib/formats/_dbf.py b/src/tablib/formats/_dbf.py index 167370373..9b3896998 100644 --- a/src/tablib/formats/_dbf.py +++ b/src/tablib/formats/_dbf.py @@ -18,7 +18,7 @@ class DBFFormat: title = 'dbf' - extensions = ('csv',) + extensions = ('dbf',) DEFAULT_ENCODING = 'utf-8' diff --git a/tests/test_tablib.py b/tests/test_tablib.py index ca8ac05ec..f49a48bd2 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -1992,6 +1992,11 @@ def test_dbf_format_detect(self): self.assertFalse(fmt.detect(_json)) self.assertFalse(fmt.detect(_bunk)) + def test_dbf_format_extension(self): + """Test the DBF format advertises its own file extension.""" + fmt = registry.get_format('dbf') + self.assertEqual(('dbf',), fmt.extensions) + class JiraTests(BaseTestCase): def test_jira_export(self):