- Issue created by @burak.ikiler
- πΉπ·Turkey burak.ikiler
Created a simple patch to fix the issues. It works well as long as energy and timestamp arenβt null or complex types like arrays/objects.
- πΊπΈUnited States tr Cascadia
That section of code should only be called if you are using a Radioactivity field instead of a Radioactivity Reference field.
In 4.1.x, you can't use a Radioactivity field unless you've upgraded an old site from 8.x-3.x and you were using the Radioactivity field in 8.x-3.x. Using the Radioactivity field is something that is supported only for backwards compatibility, but it is not allowed on new installs.
Does this correctly describe your situation?
Rather than using a cast, I would prefer to use getValue() so that the datatype of the energy and timestamp variables is maintained. They are declared as float and integer respectively, in the database schema.
- πΊπΈUnited States tr Cascadia
I moved the patch into an MR to that it can be tested.
- Merge request !45Issue #3515040 by burak.ikiler: Must be of type float, string given on calculateEnergy β (Open) created by tr
- π³π±Netherlands sysosmaster
@tr the issues stems from how PHP no longer allows old school type coercion when a specific type is enforced in a method deceleration.
I.e: the code changed by @Sutharsan in commit 1390df1149620130b83bbbb2740b846aabb0e112 has now changed meaning where it requirs the inputs to be explicitly typecast to floats / ints respectively.
you cannot depand on the database layer to do this for you since it doesn't (always) typecasts values. (it depands on its implementation and what type it is)
just casting it as this MR does would work in most cases, a better solution is to use the proper functions for it that also strip out any offending characters (since the logic of this function should be going away).
this can be done like this:
$newEnergy = $this->calculateEnergy(floatval($field->energy), intval($field->timestamp), $profile, $halfLife);
As for test examples to work on, I have the following data that triggered this bug in JSON format:
{"field->energy":"50","field->timestamp":"1741205501","profile":"decay","halflife":null} {"field->energy":"10","field->timestamp":"1741205502","profile":"decay","halflife":null} {"field->energy":"20","field->timestamp":"1741205503","profile":"decay","halflife":null} {"field->energy":"10","field->timestamp":"1741205504","profile":"decay","halflife":null} {"field->energy":"10","field->timestamp":"1741205505","profile":"decay","halflife":null} {"field->energy":"70","field->timestamp":"1741205506","profile":"decay","halflife":null} {"field->energy":"3585.97","field->timestamp":"1741205507","profile":"decay","halflife":null} {"field->energy":"40","field->timestamp":"1741205508","profile":"decay","halflife":null} {"field->energy":"3585.97","field->timestamp":"1741205509","profile":"decay","halflife":null} {"field->energy":"40","field->timestamp":"1741205510","profile":"decay","halflife":null}
I hope you now have sufficient information to process this ticket.