-
Notifications
You must be signed in to change notification settings - Fork 45
Fix DataError Due to String Length Exceeding Column Constraint in AssetAuditLog #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…dit logs and asset attribute changes Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
nhoening
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tested well!
I only have documentation improvements, let's do this.
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…event From PR #1162 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
nhoening
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adding lots of code that is hard to read, with the goal to make one message for potentially many changes at once. One more complexity problem can be seen in my one comment.
Idea: We do it simpler. Each updated field or attribute gets its own audit log, by AssetAuditLog.add_record_for_attribute_update() or AssetAuditLog.add_record().
We buy simplicity with sometimes more than one log entry. That will not happen too often I believe. And the asset audit log will be more readable.
Each message is probably short enough, but these two helper methods can still make sure by truncating if needed.
…sts before PR #1162 resolves file changes Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
* Add support for adding titles to asset page graphs * Add support for adding titles to asset page graphs #1119 * Update belief_charts.py Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com> * Update belief_charts.py Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com> * Update belief_charts.py Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com> * Update Files Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Refactor: Move sensor_to_show to SensorToShowSchema from GenericAssetSchema and Able to handle both 'sensor' and 'sensors' inputs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Update: Modify sensors_to_show method in GenericAsset to handle both 'sensor' and 'sensors' inputs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Update: chart_for_multiple_sensors to handle both 'sensor' and 'sensors' inputs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Update: flatten_unique to handle both 'sensor' a nd 'sensors' inputs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Resolve audit_log by truncating event string Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * update assets.py and audit_log with new truncate string and truncate event From PR #1162 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * refactor chart_for_multiple_sensors to show titles as graph titles not axis titles Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Refactor SensorsToShowSchema to handle true deserialization and validation Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * refactor sensors_to_show property to utilize SensorsToShowSchema Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * refactor flatten_unique Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Add Tests for SensorsToShowSchema Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * run pre-commit Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * update test_alter_an_asset_with_bad_json_attributes params Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Improve validation error messages for 'sensors_to_show' Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Update tests to handle new event string and validation error message for 'sensors_to_show' Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Temporarily refactor audit_log.py and assets.py to address failing tests before PR #1162 resolves file changes Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Add changelog entry and note in docs asset page Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * focus changelog entry more on the end result (what users care about) Signed-off-by: Nicolas Höning <nicolas@seita.nl> * give the sensors_to_show attribute a more meaningful place in the docs Signed-off-by: Nicolas Höning <nicolas@seita.nl> --------- Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com> Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> Signed-off-by: Nicolas Höning <nicolas@seita.nl> Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
… update get's it's own entry Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
|
Can you bring the PR description up to date? |
nhoening
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it (still) works.
Can you quickly add a changelog entry and add one semi-colon for me?
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
nhoening
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
This PR introduces changes to prevent string length exceeding column size in the
AssetAuditLogby implementing updating audit_log for each asset or attribute change individually and truncation for long strings (exceeding 255).Added the
truncate_stringfunction to handle string truncation, ensuring compliance with the 255-character limit on the event field in theAssetAuditLogtable by adding...in middle of string.Updated the
AssetAuditLogclass to ensure each asset update or feature change is logged as a separate entry. This prevents exceeding the column size limit by breaking up large events into individual records.Look & Feel
changing an asset attribute From:
To:
would result in 5
audit_loginstead of 1 long one that would exceed column length:Updated asset 'toy-battery': 3 fields: Attr: capacity_in_mw, From: 0.5, To: 0.05Updated asset 'toy-battery': 3 fields: Attr: max_soc_in_mwh, From: 0.45, To: 0.045Updated asset 'toy-battery': 3 fields: Attr: min_soc_in_mwh, From: 0.05, To: 5Updated asset 'toy-battery-1': 3 fields: Attr: sensors_to_show, From: [{'title': 'Test Title 1', 'sensors': [1]}, {'title': ' ... e': 'Test Title 3', 'sensors': [2, 5]}, {'title': 'Test Title 4', 'sensors': [1]}, {'title': 'Test Title 5', 'sensors': [1]}] (This event was truncated by adding ' ... ' in middle because event was over 255 limit)How to test
Reproduce the Issue:
sensors_to_showfield with JSON data such as:{ "sensors_to_show": [[129, 125, 119], [129, 125, 119], [129, 125, 119], [129, 125, 119], [129, 125, 119], [129, 125, 119], [129, 125, 119]] }sensors_to_showto trigger the error.Verify Fix:
DataErroroccurs.Further Improvements
Related Items
closes #1136