dasch / avro_turf

A library that makes it easier to use the Avro serialization format from Ruby.
MIT License
167 stars 80 forks source link

Fix AvroTurf::SchemaStore#load_schemas! depends on file order #185

Closed piotaixr closed 1 year ago

piotaixr commented 1 year ago

This happens because when loading schemas using find, the already loaded schemas are not provided to load_schema!. With Schema Z being required by schema X itself required by schema Y, and schemas being loaded in alphabetical order, when loading Y, local_schemas_cache is empty when load_schema!(Y) is called. This makes parsing the schema fails because X is unknown (to load_schema!, even if present in @schemas). An attempt is made to have X loaded, to local_schemas_cache This fails because Z is not in local_schemas_cache Z is loaded, and added to local_schemas_cache Then, a second attempt is made to load X, but providing @schemas, this time. Avro fails, because X is already loaded

This change basically provides @schemas.dup when find calls load_schema! to make sure X is found on first try.

Fixes #181