Null values
ctmay4 opened this issue · 4 comments
ctmay4 commented
Initial context is designed to set initial values in a context at the start of staging or at the start of a mapping. It looks like:
"initial_context": [
{
"key": "test",
"value": "something"
}
]
What would it mean if the value above was null?
I see two options.
- Assume null means empty string.
- Assume null means to remove the key from the context.
I prefer the second option since it gives the ability to do something that is not possible right now. If you want to set a value to blank you can easily do that. However there is no other way to remove a key from the context in the processing of staging call.
ctmay4 commented
The handling of null values goes beyond just initial context. Here are the cases so far:
- User entered context for staging. In this case I currently translate nulls to blanks. I could also see failing if null is supplied because it doesn’t make sense. Probably failing would be more “clear”.
- Default values. In this case, I also think null should be disallowed. What does that mean? I can convert it to blank if we want, but disallowing it makes things more clear.
- Initial context. This is the only case where I can see value in null. I could make it so when it is null, that means that you want the key removed from the context. Alternatively, I could be consistent and just disallow null values here. However I think the ability to remove context keys could come in useful.
stealthv commented
We had a conversation about this and here is what I took away:
- User entered context for staging. These will no longer be immediately converted to blanks if null. That turned out to actually be a bug since it was bypassing the use of default values.
- If there is no default value then that will be stored by the absense of the default_value key (not by using null or an empty string). During staging any incoming value of null will use the default_value (if missing the default_value will appear as null). If that is also null then the value will be converted to blank.
- Initial context should never have null stored as a value. It needs to have a value (empty string or otherwise).
ctmay4 commented
After discussing this with Bran, here are the changes:
- on values passed in to stage, don't immediately set nulls to blanks since it was interfering with default values
default_value
does not have to be supplied in the inputs; not supplying it is assumed to be a default value of blank- if an input is not passed in and there is no default value, default that key to blank in the context.
- as for
initial_context
, it should never have null values. Those values will be ignored (although the editor should not allow it)
ctmay4 commented
This was fixed with the 1.2 release.