Refactor all *.from_db() routines to use from_db_json() #821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stacked on top of PR #659 (but for merging into dev after that one has been merged), this refactors existing code to use
from_db_json()
, newly added in the multiple external-ids PR.This wrapper calls json.loads() but also handles None (returning None), which enables the code at many call sites to be simplified.
Removed some callers'
if isinstance(field, str): ...
code, which has the effect of newly disallowing field values that are already dicts. However we've verified that all *.from_db() calls have raw database outputs as their arguments, so such fields will be always be strings and IMHO giving a dict to from_db_json() is really a logic error that should be detected.In SequencingGroupInternal.from_db() added
pop(..., None)
so that a missing meta field is now accepted. The previous code suggests that having pop() produce KeyError here was unintended.The expected argument types for from_db_json() are listed in the definition, but we don't list its return type. The best we could say in general is
object
but most call sites expectdict[str, str]
(or occasionallylist[str]
) due to the shape of their expected JSON. Specifyingobject
would lead to mypy errors at these call sites.I suppose we could have a
dict_from_db_json()
routine for the common case of metadict[str,str]
expansion that could have that return type annotation and could even validate that the JSON was of the expected form! But I think that would be overkill…