I've got a D8 media type that holds information obtained from an external source. The information comes in name value pairs that I wish to save as individual fields, mostly so I can index them easily with solr. On some files I get new property names that have to be persisted as fields, so I have a presave hook that creates and saves a FieldStorageConfig, and a StorageConfig for my each new field in my media bundle. It all works swimmingly.
THe problem is when i try to save a value to that new field in the presave function an error is thrown indicating that the field doesn't exist. (It does exist, but Drupal doesn't know about it yet). When I resave the media with the same input file everything goes as planned.
Is there a way to force Drupal to refresh the media's field list?