Scrapy, a fast high-level web crawling & scraping framework for Python.
support FEED_EXPORT_FIELDS=[]
Mikhail Korobov9fb318338bb4
diff --git a/docs/topics/feed-exports.rst b/docs/topics/feed-exports.rstindex ea4cc2162..f4fb07761 100644--- a/docs/topics/feed-exports.rst+++ b/docs/topics/feed-exports.rst@@ -236,17 +236,20 @@ The serialization format to be used for the feed. SeeFEED_EXPORT_FIELDS------------------+Default: ``None``+A list of fields to export, optional.Example: ``FEED_EXPORT_FIELDS = ["foo", "bar", "baz"]``.Use FEED_EXPORT_FIELDS option to define fields to export and their order.-When omitted or empty, Scrapy uses fields defined in :class:`~.Item` subclasses-a spider is yielding. If raw dicts are used as items, FEED_EXPORT_FIELDS-is omitted and an exporter requires a fixed set of fields (this is the case-for :ref:`CSV <topics-feed-format-csv>` export format) then Scrapy tries-to infer field names from the exported data - currently it uses field names-from the first item.+When FEED_EXPORT_FIELDS is None (default), Scrapy uses fields+defined in :class:`~.Item` subclasses a spider is yielding.+If FEED_EXPORT_FIELDS is None, raw dicts are used as items and+an exporter requires a fixed set of fields (this is the case for+:ref:`CSV <topics-feed-format-csv>` export format), then+Scrapy tries to infer field names from the exported data - currently it+uses field names from the first item... setting:: FEED_STORE_EMPTYdiff --git a/scrapy/extensions/feedexport.py b/scrapy/extensions/feedexport.pyindex 7a1a02be1..08e868c9f 100644--- a/scrapy/extensions/feedexport.py+++ b/scrapy/extensions/feedexport.py@@ -151,7 +151,12 @@ class FeedExporter(object):if not self._exporter_supported(self.format):raise NotConfiguredself.store_empty = settings.getbool('FEED_STORE_EMPTY')- self.export_fields = settings.getlist('FEED_EXPORT_FIELDS') or None++ if settings.get('FEED_EXPORT_FIELDS') is None:+ self.export_fields = None # don't promote None to []+ else:+ self.export_fields = settings.getlist('FEED_EXPORT_FIELDS')+uripar = settings['FEED_URI_PARAMS']self._uripar = load_object(uripar) if uripar else lambda x, y: Nonediff --git a/tests/test_feedexport.py b/tests/test_feedexport.pyindex efee9bf94..c3d8b64ef 100644--- a/tests/test_feedexport.py+++ b/tests/test_feedexport.py@@ -246,6 +246,10 @@ class FeedExportTest(unittest.TestCase):yield self.assertExported(items, header, rows,settings=settings, ordered=True)+ # edge case: FEED_EXPORT_FIELDS==[] means nothing is exported+ settings = {'FEED_EXPORT_FIELDS': []}+ yield self.assertExportedJsonLines(items, [{},{},{},{}], settings)+@defer.inlineCallbacksdef test_export_dicts(self):# When dicts are used, only keys from the first row are used as