Safely handle inserting object field values
JoshWillik opened this issue · 0 comments
JoshWillik commented
Problem
Hi, I was trying to insert a uuid into a record, and it caused a 400 error because the finished record looked like this
event,foo=bar id=a605d377-47bd-4d9a-8b6e-c9ed66bed255
The error occurs because the uuid isn't quoted:
event,foo=bar id="a605d377-47bd-4d9a-8b6e-c9ed66bed255"
This is because the uuid was a Uuid object, not a string (which I didn't realize at the time).
Solution
This function should stringify objects before processing them.
if (is_object($field) {
$field = $field->toString();
}
The object will eventually be stringified when inserted into the line record, so may as well do it early so it can be quoted if needed.