Skip to content

Commit cfc2d46

Browse files
committed
backport master fixes to json exporter
1 parent 06149e0 commit cfc2d46

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

scrapy/contrib/exporter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _get_serialized_fields(self, item, default_value=None, include_empty=None):
7979
class JsonLinesItemExporter(BaseItemExporter):
8080

8181
def __init__(self, file, **kwargs):
82-
self._configure(kwargs)
82+
self._configure(kwargs, dont_fail=True)
8383
self.file = file
8484
self.encoder = ScrapyJSONEncoder(**kwargs)
8585

@@ -91,7 +91,7 @@ def export_item(self, item):
9191
class JsonItemExporter(JsonLinesItemExporter):
9292

9393
def __init__(self, file, **kwargs):
94-
self._configure(kwargs)
94+
self._configure(kwargs, dont_fail=True)
9595
self.file = file
9696
self.encoder = ScrapyJSONEncoder(**kwargs)
9797
self.first_item = True

scrapy/tests/test_contrib_exporter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ def test_nested_item(self):
233233
exported = json.loads(self.output.getvalue())
234234
self.assertEqual(exported, self._expected_nested)
235235

236+
def test_extra_keywords(self):
237+
self.ie = self._get_exporter(sort_keys=True)
238+
self.test_export_item()
239+
self._check_output()
240+
self.assertRaises(TypeError, self._get_exporter, foo_unknown_keyword_bar=True)
241+
242+
236243
class JsonItemExporterTest(JsonLinesItemExporterTest):
237244

238245
_expected_nested = [JsonLinesItemExporterTest._expected_nested]

0 commit comments

Comments
 (0)