Repository navigation
Fix TypeError when hydrating time_unit on ticket articles - #196
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 1
Please check the settings in the CodeRabbit UI or the
|
derpixler
left a comment
There was a problem hiding this comment.
Hi @jorisdrenth, thanks for the fix and the clear write-up. Good catch that the old test used a native float.
Just the few inline comments left to address, then it's good to go.
When we switched on time accounting in Zammad settings, our implementation gave an error:
I found Zammad stores
time_unitas a decimal column, which the API returns as a JSON string (e.g."15.0").DtoHydrator::coerce()had no branch forfloat, so the raw string was passed intoTicketArticleDTO's?float $time_unitparameter.The existing unit test used a native float (
5.5), so it didn't catch this.Changes:
Cast::floatOrNull(): returns a float for numeric values (including numeric strings),nullotherwise.floatbranch toDtoHydrator::coerce(), mirroringint: nullable parameters useCast::floatOrNull(), non-nullable ones use a newrequireFloat()that throws aRuntimeExceptionwhen the field is missing or not numeric.TicketArticleDTOTestfortime_unitas a decimal string, fractional string, integer string, integer, float,null, and a missing key.Summary by CodeRabbit