mirror of https://github.com/scrapy/scrapy.git
drop support for FEED_EXPORT_FIELD=[] meaning "no fields"
This commit is contained in:
parent
9fb318338b
commit
9b0ca1b7a0
|
|
@ -243,13 +243,13 @@ Example: ``FEED_EXPORT_FIELDS = ["foo", "bar", "baz"]``.
|
|||
|
||||
Use FEED_EXPORT_FIELDS option to define fields to export and their order.
|
||||
|
||||
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.
|
||||
When FEED_EXPORT_FIELDS is empty or None (default), Scrapy uses fields
|
||||
defined in dicts or :class:`~.Item` subclasses a spider is yielding.
|
||||
|
||||
If an exporter requires a fixed set of fields (this is the case for
|
||||
:ref:`CSV <topics-feed-format-csv>` export format) and FEED_EXPORT_FIELDS
|
||||
is empty or None, then Scrapy tries to infer field names from the
|
||||
exported data - currently it uses field names from the first item.
|
||||
|
||||
.. setting:: FEED_STORE_EMPTY
|
||||
|
||||
|
|
|
|||
|
|
@ -151,12 +151,7 @@ class FeedExporter(object):
|
|||
if not self._exporter_supported(self.format):
|
||||
raise NotConfigured
|
||||
self.store_empty = settings.getbool('FEED_STORE_EMPTY')
|
||||
|
||||
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')
|
||||
|
||||
self.export_fields = settings.getlist('FEED_EXPORT_FIELDS') or None
|
||||
uripar = settings['FEED_URI_PARAMS']
|
||||
self._uripar = load_object(uripar) if uripar else lambda x, y: None
|
||||
|
||||
|
|
|
|||
|
|
@ -234,7 +234,12 @@ class FeedExportTest(unittest.TestCase):
|
|||
yield self.assertExportedCsv(items, header, rows_csv, ordered=False)
|
||||
yield self.assertExportedJsonLines(items, rows_jl)
|
||||
|
||||
# but it is possible to override fields using FEED_EXPORT_FIELDS
|
||||
# edge case: FEED_EXPORT_FIELDS==[] means the same as default None
|
||||
settings = {'FEED_EXPORT_FIELDS': []}
|
||||
yield self.assertExportedCsv(items, header, rows_csv, ordered=False)
|
||||
yield self.assertExportedJsonLines(items, rows_jl, settings)
|
||||
|
||||
# it is possible to override fields using FEED_EXPORT_FIELDS
|
||||
header = ["foo", "baz", "hello"]
|
||||
settings = {'FEED_EXPORT_FIELDS': header}
|
||||
rows = [
|
||||
|
|
@ -246,10 +251,6 @@ 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.inlineCallbacks
|
||||
def test_export_dicts(self):
|
||||
# When dicts are used, only keys from the first row are used as
|
||||
|
|
|
|||
Loading…
Reference in New Issue