FlexMeasures / flexmeasures

The intelligent & developer-friendly EMS to support real-time energy flexibility apps, rapidly and scalable.
https://flexmeasures.io
Apache License 2.0
145 stars 36 forks source link

DataError Due to String Length Exceeding Column Constraint in AssetAuditLog #1136

Closed BelhsanHmida closed 1 month ago

BelhsanHmida commented 2 months ago

Description:

When working on the Add support for adding titles to asset page graphs #1125 to add support for titles in asset page graphs, i encountered a DataError: ERROR: DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(255)

Steps to Reproduce:

  1. Use the following JSON to add titles to asset page graphs on 1119-add-titles-to-asset-graphs Branch : { "sensors_to_show": [ {"title": "Test 1", "sensor": 4612}, {"title": "Test 2", "sensors": [4613, 1]}, {"title": "Test 3", "sensors": [4613]}, {"title": "Final Test", "sensors": [1]} ] }

  2. Attempt to add or update the asset page with the above data.

Explanation:

The DataError occurs because the length of the string data being inserted or updated exceeds the maximum allowed length of 255 characters for a character varying(255) column in the database. This often happens when the data being handled (in this case, the titles or sensor identifiers) is too lengthy for the defined column size in the database schema.

Possible Solution:

nhoening commented 2 months ago

Good catch!

I believe we should make sure that the entry about a new attribute will not become too long in AssetAuditLog.add_record_for_attribute_update() and maybe also add_record().

Also, we could make that column somewhat larger, e.g. 500 characters.