Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commitWithin gives serializing error #42

Closed
wichert opened this issue Mar 6, 2012 · 6 comments
Closed

commitWithin gives serializing error #42

wichert opened this issue Mar 6, 2012 · 6 comments
Labels

Comments

@wichert
Copy link

wichert commented Mar 6, 2012

An extract from our errors logs (running under mod_wsgi):

[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     solr.add([data], commit=None, commitWithin=60 * 1000)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/opt/s4uadmin/eggs/pysolr-2.0.15-py2.7.egg/pysolr.py", line 686, in add
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     m = ET.tostring(message, encoding='utf-8')
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1121, in tostring
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     ElementTree(element).write(file, encoding, method=method)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 815, in write
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     serialize(write, self._root, encoding, qnames, namespaces)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 927, in _serialize_xml
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     v = _escape_attrib(v, encoding)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1087, in _escape_attrib
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     _raise_serialization_error(text)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1047, in _raise_serialization_error
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1]     "cannot serialize %r (type %s)" % (text, type(text).__name__)
[Tue Mar 06 10:11:10 2012] [error] [client 127.0.0.1] TypeError: cannot serialize 60000 (type int)
@toastdriven
Copy link
Collaborator

Bizarre. No clue what's going wrong here, since etree has no problems serializing integers. Using pdb to inspect the message (pysolr.py, line 686 from the traceback) would probably be informative.

@wichert
Copy link
Author

wichert commented Apr 20, 2012

pdb under mod_wsgi in production isn't really an option I'm afraid, and I haven't been able to reproduce this in a test environment.

@toastdriven
Copy link
Collaborator

Then perhaps setting up a try/except block that catches the error & logs what was sent? You might also try installing lxml, as it looks like you're falling back on Python's etree, which sometimes has subtle differences from lxml.etree.

@tleach
Copy link

tleach commented Oct 22, 2012

We just hit this. Can pysolr not simply do the type conversion of the commitWithin arg from int -> str?

Happy to contribute a PR if so desired.

@acdha
Copy link
Collaborator

acdha commented Oct 22, 2012

This is an annoying limitation in etree:

>>> from xml.etree.ElementTree import Element, ElementTree
>>> import sys
>>> ElementTree(Element(42)).write(sys.stdout)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 812, in write
    self._root, encoding, default_namespace
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 881, in _namespaces
    _raise_serialization_error(tag)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1047, in _raise_serialization_error
    "cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize 42 (type int)

Since ElementTree is [arguably] braindead I'd vote for a pull request adding an str() call on pysolr.py#L689 and, ideally, a test exercising this path.

@stale
Copy link

stale bot commented Jun 5, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 5, 2018
@stale stale bot closed this as completed Jul 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants