Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle partial API POST and PUT requests #18

Open
gassc opened this issue Feb 21, 2018 · 1 comment
Open

handle partial API POST and PUT requests #18

gassc opened this issue Feb 21, 2018 · 1 comment
Assignees

Comments

@gassc
Copy link
Member

gassc commented Feb 21, 2018

Need add'l logic and tests to make sure that the API methods can handle partial submissions, and elegantly fill in the blanks for non-mandatory fields. I think right now it might be rejecting anything less than a full fish fry feature.

@gassc
Copy link
Member Author

gassc commented Sep 22, 2018

I've sorted out how to do this, with the generous help of Stack Overflow:

def deep_merge(d, u):
   """Do a deep merge of one dict into another.
   This will update d with values in u, but will not delete keys in d
   not found in u at some arbitrary depth of d. That is, u is deeply
   merged into d.
   Args -
     d, u: dicts
   Note: this is destructive to d, but not u.
   Returns: None
   """
   stack = [(d,u)]
   while stack:
      d,u = stack.pop(0)
      for k,v in u.items():
         if not isinstance(v, collections.Mapping):
            # u[k] is not a dict, nothing to merge, so just set it,
            # regardless if d[k] *was* a dict
            d[k] = v
         else:
            # note: u[k] is a dict

            # get d[k], defaulting to a dict, if it doesn't previously
            # exist
            dv = d.setdefault(k, {})

            if not isinstance(dv, collections.Mapping):
               # d[k] is not a dict, so just set it to u[k],
               # overriding whatever it was
               d[k] = v
            else:
               # both d[k] and u[k] are dicts, push them on the stack
               # to merge
               stack.append((dv, v))

This would happen somewhere in db_interface.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant