From bb2cf7c0d7199fffe0aa100e5c8a51c6b4b82fc2 Mon Sep 17 00:00:00 2001 From: stummjr Date: Fri, 29 Jan 2016 19:23:26 -0200 Subject: [PATCH] Fixed bug on XMLItemExporter with non-string fields in items --- scrapy/exporters.py | 4 +++- tests/test_exporters.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scrapy/exporters.py b/scrapy/exporters.py index 35f50838b..360007c0f 100644 --- a/scrapy/exporters.py +++ b/scrapy/exporters.py @@ -144,8 +144,10 @@ class XmlItemExporter(BaseItemExporter): elif is_listlike(serialized_value): for value in serialized_value: self._export_xml_field('value', value) - else: + elif isinstance(serialized_value, six.text_type): self._xg_characters(serialized_value) + else: + self._xg_characters(str(serialized_value)) self.xg.endElement(name) # Workaround for http://bugs.python.org/issue17606 diff --git a/tests/test_exporters.py b/tests/test_exporters.py index 7ba5a0af6..cd72c661a 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -376,6 +376,20 @@ class XmlItemExporterTest(BaseItemExporterTest): b'' ) + def test_nonstring_types_item(self): + item = self._get_nonstring_types_item() + self.assertExportResult(item, + b'\n' + b'' + b'' + b'3.14' + b'False' + b'22' + b'' + b'' + b'' + ) + class JsonLinesItemExporterTest(BaseItemExporterTest):