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:
parent
6bad987f38
commit
d0fdc56890
4 changed files with 65 additions and 2 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue