You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
I think we've noticed a behavior which is not backward compatible with endpoints v1.
In v1, when the app is deployed (does not happen on the dev server), all empty values (None, (), {}, []) are removed from messages by the endpoints lib.
For instance :
d = {}
d['first'] = 'one'
d['two'] = {}
is transformed in {"first": "one"} in v1 and in {"first": "one", "two": {}} in v2.
Is this by design or is it a bug that will be fixed?
Here is the monkey patch we use:
fromprotorpc.protojsonimportMessageJSONEncoderendpoints_original_method=MessageJSONEncoder.defaultdefdel_none(d):
""" Delete keys with the value ``None`` in a dictionary, recursively. http://stackoverflow.com/questions/4255400/exclude-empty-null-values-from-json-serialization This alters the input so you may wish to ``copy`` the dict first. Args: d: the value to remove empty values from. """ifisinstance(d, dict):
forkey, valueind.items():
ifvaluein (None, [], (), {}, ):
deld[key]
elifisinstance(value, dict):
del_none(value)
returnddefdefault(self, value):
""" Monkey patch the SDK method to remove empty values. Replicate the behavior of the prod endpoints. Args: value: Value to get dictionary for. """returndel_none(endpoints_original_method(self, value))
MessageJSONEncoder.default=default
Does this behavior persist if you assign an empty list or tuple? Looking through the code, it appears that the intent is to remove NoneType values and empty lists/tuples, but not empty dicts. However, if the v1 behavior was to remove empty dicts as well, I can continue to look into this. Thanks!
Activity
bradfriedman commentedon Feb 1, 2017
Does this behavior persist if you assign an empty list or tuple? Looking through the code, it appears that the intent is to remove NoneType values and empty lists/tuples, but not empty dicts. However, if the v1 behavior was to remove empty dicts as well, I can continue to look into this. Thanks!
emelois commentedon Feb 2, 2017
You're right, it seems to be the case only for empty dicts. I confirm that they were removed in v1.
nilleb commentedon Nov 8, 2017
@bradfriedman anything new on this?
inklesspen commentedon Nov 8, 2017
Brad is no longer on the team.
nilleb commentedon Nov 8, 2017
inklesspen commentedon Nov 8, 2017
I have only just seen this issue. I will look into it.
lcasartelli commentedon Dec 9, 2017
+1 any news on this? I am experiencing the same behavior.