dbt-labs / hologram

A library for automatically generating Draft 7 JSON Schemas from Python dataclasses
MIT License
9 stars 13 forks source link

improve thread safety #25

Closed beckjake closed 5 years ago

beckjake commented 5 years ago

Some fixes to provide thread safety in hologram.

Before this patch, if you called json_schema() for the same object across multiple threads at the same time, you would (sometimes!) get a SchemaError about None is not of type 'object', 'boolean' with references to schema['definitions']. The fix is to create a global lock around all writes to _schema, with checks for the happy path to avoid hitting the lock too frequently.