Aasher commited on
Commit
f39d924
·
1 Parent(s): 82a9011

fix: truncate thread name to 200 characters in update_thread method to prevent database errors

Browse files
Files changed (1) hide show
  1. data_layer.py +33 -0
data_layer.py CHANGED
@@ -146,3 +146,36 @@ class CustomPostgresDataLayer(SQLAlchemyDataLayer):
146
  paginated_response = await super().list_threads(pagination, filters)
147
  paginated_response.data = self._clean_datetimes(paginated_response.data)
148
  return paginated_response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  paginated_response = await super().list_threads(pagination, filters)
147
  paginated_response.data = self._clean_datetimes(paginated_response.data)
148
  return paginated_response
149
+
150
+ async def update_thread(
151
+ self,
152
+ thread_id: str,
153
+ name: Optional[str] = None,
154
+ user_id: Optional[str] = None,
155
+ metadata: Optional[Dict] = None,
156
+ tags: Optional[list[str]] = None,
157
+ ):
158
+ """
159
+ Overrides the base method to truncate the thread name to 200 characters
160
+ before saving, preventing database errors with long first messages.
161
+ """
162
+
163
+ # Determine the effective name from parameters or metadata
164
+ effective_name = name
165
+ if not effective_name and metadata and "name" in metadata:
166
+ effective_name = metadata.get("name")
167
+
168
+ # Truncate the name to a safe length
169
+ if effective_name:
170
+ truncated_name = effective_name[:200]
171
+ else:
172
+ truncated_name = None
173
+
174
+ # Now, call the original method from the base class with the truncated name
175
+ await super().update_thread(
176
+ thread_id=thread_id,
177
+ name=truncated_name,
178
+ user_id=user_id,
179
+ metadata=metadata,
180
+ tags=tags
181
+ )