fix: truncate "params" column on vertex_build table to prevent memory heap on database (#4118)

* ✨ (model.py): add new method `serialize_params` to serialize parameters data in VertexBuildBase class

* 🐛 (util_strings.py): fix truncation logic to correctly handle long strings by truncating them with ellipsis if they exceed the maximum length

* ✅ (test_truncate_long_strings.py): add unit tests for the truncate_long_strings function to ensure it works correctly with various input scenarios

* ✅ (test_truncate_long_strings_on_objects.py): update test assertion message to reflect the expected behavior of the function
This commit is contained in:
Cristhian Zanforlin Lousa 2024-10-11 15:10:36 -03:00 • committed by GitHub
commit d0fdc56890
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 2 deletions

View file

@ -49,6 +49,10 @@ class VertexBuildBase(SQLModel):
def serialize_artifacts(self, data) -> dict:
return truncate_long_strings(data)
@field_serializer("params")
def serialize_params(self, data) -> dict:
return truncate_long_strings(data)
class VertexBuildTable(VertexBuildBase, table=True): # type: ignore[call-arg]
__tablename__ = "vertex_build"

View file

@ -9,7 +9,12 @@ def truncate_long_strings(data, max_length=None):
if max_length is None:
max_length = constants.MAX_TEXT_LENGTH
if max_length < 0 or not isinstance(data, dict | list):
if max_length < 0:
return data
if not isinstance(data, dict | list):
if isinstance(data, str) and len(data) > max_length:
return data[:max_length] + "..."
return data
if isinstance(data, dict):