Must be of type float, string given on calculateEnergy

Created on 24 March 2025, 10 days ago

Problem/Motivation

When running cron manually, following errors is thrown.

TypeError: Drupal\radioactivity\RadioactivityProcessor::calculateEnergy(): Argument #1 ($energy) must be of type float, string given, called in /var/www/html/docroot/modules/contrib/radioactivity/src/RadioactivityProcessor.php on line 308 in Drupal\radioactivity\RadioactivityProcessor->calculateEnergy() (line 348 of modules/contrib/radioactivity/src/RadioactivityProcessor.php).

Steps to reproduce

Select the "Run cron" option on admin toolbar

Proposed resolution

Remaining tasks

User interface changes

Nothing

API changes

Nothing

Data model changes

Nothing

πŸ› Bug report
Status

Active

Version

4.1

Component

Code

Created by

πŸ‡ΉπŸ‡·Turkey burak.ikiler

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • 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.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024