You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling pysolr.Solr.add with a dict containing a datetime object causes the following stack trace:
File "<>/.local/lib/python3.7/site-packages/pysolr.py", line 1018, in add
m = json.dumps(message).encode("utf-8")
File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable
Before this change the datetime object could propagate via self._build_doc to self._from_python where the first check would have converted it to a string.
I have
Tested with the latest release
Tested with the current master branch
Searched for similar existing issues
Expected behaviour
No exception
Actual behaviour
TypeError: Object of type datetime is not JSON serializable
Configuration
Operating system version: debian 10
Search engine version: 8.5.1
Python version: 3.7
pysolr version: 3.9.0
The text was updated successfully, but these errors were encountered:
You can go back to using the XML interface using the optional parameter, call isoformat() on the date objects before passing them in. It would be nice if we had a JSON encoder which handles this, too, if you have time to contribute one.
Thanks for the suggestion.
I am now just passing datetime(...).isoformat() instead of datetime(...) and everything works fine. I did not try the XML interface.
Regarding the encoder, I will not have the time, unfortunately.
Calling
pysolr.Solr.add
with a dict containing adatetime
object causes the following stack trace:I believe this change to be the breaking change.
Before this change the datetime object could propagate via
self._build_doc
toself._from_python
where the first check would have converted it to a string.I have
Expected behaviour
No exception
Actual behaviour
TypeError: Object of type datetime is not JSON serializable
Configuration
The text was updated successfully, but these errors were encountered: