Problem/Motivation
We're facing an issue with a custom sensor which checks for module updates, where the data that needs to be stored in the 'sensor message' is too long for the column type.
The PHP error thrown is the following:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'sensor_message' at row 1: INSERT INTO {monitoring_sensor_result} (sensor_name, sensor_status, sensor_message, sensor_value, timestamp, execution_time)...
We don't have the same issue with the module installed on D8 sites with the same custom sensor and upon comparing the 'sensor_message' column on both D7 and D8 we've noticed they are different types.
On D7 it is a 'text' type which means it's limited to 65,535 characters, whereas on D8 the sensor entity's message field is a 'longtext' which means it's limited to 4,294,967,295 characters which is why it's not failing on D8.
Proposed resolution
Create a patch to update the 'sensor_message' column type to 'longtext' in the monitoring_schema() hook, and a hook_update() to change the column type on sites that have the module already installed.
Remaining tasks
Create patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3137770-2.monitoring.Data-too-long-for-column-sensormessage.patch | 770 bytes | oldspot |
Comments
Comment #2
oldspot commentedCreated patch to update the column type to 'longtext', which technically in Drupal is just setting the 'size' to 'big' on the 'text' type.
Tested it on our site and updates the column fine and no more error when running the sensor.