JSONStore uses the read_json_file method during connect to aggregate contents of one or more json files into a MemoryStore. This PR contains several quality of life improvements to make this method more reliable and easier to debug.
Changes
Currently, if any of the json files is improperly formatted or otherwise causes an error, connect fails and it is very difficult to determine the reason. This PR the read_json_file call in a try/except block and adds logging messages that make it easier to tell which file is causing the problem, and what the error is.
Currently, read_json_files uses zopen to access each file in read-write mode. This is unnecessary and can contradict the spirit of the read_only kwarg. This PR change the zopen call to read-only.
If a JSON file contents do not contain a last_updated field, one will now be added (and set to the current time)
If a JSON file DOES contain a last_updated field but was serialized using montydumpfn, the field will be a complete dict version of a datetime object, e.g.
JSONStore
uses theread_json_file
method duringconnect
to aggregate contents of one or more json files into aMemoryStore
. This PR contains several quality of life improvements to make this method more reliable and easier to debug.Changes
connect
fails and it is very difficult to determine the reason. This PR theread_json_file
call in a try/except block and adds logging messages that make it easier to tell which file is causing the problem, and what the error is.read_json_files
useszopen
to access each file in read-write mode. This is unnecessary and can contradict the spirit of theread_only
kwarg. This PR change thezopen
call to read-only.last_updated
field, one will now be added (and set to the current time)monty
dumpfn
, the field will be a completedict
version of adatetime
object, e.g.This PR adds logic to
read_json_files
that will replacelast_updated
with just the contents ofstring
, because that is whatmaggma
expects.