Skip to content

Solr.add with datetime instance causes TypeError #317

Description

@o-felixz

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

I believe this change to be the breaking change.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions