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

Error if nested data contains a date #1

simonw opened this issue Nov 29, 2019 · 1 comment

Error if nested data contains a date #1

simonw opened this issue Nov 29, 2019 · 1 comment


Copy link

@simonw simonw commented Nov 29, 2019


   id: 49
   name: jAdis
   - title: Title
   - date: 2018-11-01

Produces this error:

~ $ yaml-to-sqlite /tmp/h.db h /tmp/h.yaml 
Traceback (most recent call last):
  File "/usr/local/bin/yaml-to-sqlite", line 11, in <module>
  File "/usr/local/lib/python3.7/site-packages/click/", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/yaml_to_sqlite/", line 17, in cli
    db[table].upsert_all(yaml.safe_load(yaml_file), pk=pk)
  File "/usr/local/lib/python3.7/site-packages/sqlite_utils/", line 1094, in upsert_all
  File "/usr/local/lib/python3.7/site-packages/sqlite_utils/", line 1015, in insert_all
    record.get(key, None if key != hash_id else _hash(record))
  File "/usr/local/lib/python3.7/site-packages/sqlite_utils/", line 1202, in jsonify_if_needed
    return json.dumps(value)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

Found this bug while working on simonw/museums#7

@simonw simonw added the bug label Nov 29, 2019

This comment has been minimized.

Copy link
Owner Author

@simonw simonw commented Nov 29, 2019

Maybe this bug is in sqlite-utils? Should that be able to handle dates?

I don't think so. The fact that dates are present here is a YAML thing.

@simonw simonw closed this in 0d58154 Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.