Skip to content

Parse all the datetimes before sending to webhooks#3657

Merged
mdmohsin7 merged 1 commit into
mainfrom
pusher-webhook-fix
Dec 8, 2025
Merged

Parse all the datetimes before sending to webhooks#3657
mdmohsin7 merged 1 commit into
mainfrom
pusher-webhook-fix

Conversation

@mdmohsin7
Copy link
Copy Markdown
Member

image

@mdmohsin7 mdmohsin7 changed the title Parse all the datetimes before sending to pusher Parse all the datetimes before sending to webhooks Dec 8, 2025
@mdmohsin7 mdmohsin7 merged commit a02d6b4 into main Dec 8, 2025
1 check passed
@mdmohsin7 mdmohsin7 deleted the pusher-webhook-fix branch December 8, 2025 16:07
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a much-needed improvement by centralizing datetime serialization to ISO format. The new recursive approach in as_dict_cleaned_dates is robust and handles nested structures effectively. However, there are significant code duplication issues and a redundant serialization call that need to be addressed to maintain code quality and efficiency.

Comment on lines +393 to +402
def convert_datetime_to_iso(obj):
"""Recursively convert datetime objects to ISO format strings"""
if isinstance(obj, datetime):
return obj.isoformat()
elif isinstance(obj, dict):
return {key: convert_datetime_to_iso(value) for key, value in obj.items()}
elif isinstance(obj, list):
return [convert_datetime_to_iso(item) for item in obj]
else:
return obj
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The convert_datetime_to_iso function introduced here implements a recursive datetime serialization logic. This exact same logic is duplicated in backend/utils/app_integrations.py and backend/utils/webhooks.py. To improve maintainability and adhere to the DRY principle, please extract this common utility into a shared module (e.g., backend/utils/serialization_utils.py) and import it where needed.

Comment on lines +26 to +35
def _json_serialize_datetime(obj: Any) -> Any:
"""Helper function to recursively convert datetime objects to ISO format strings for JSON serialization"""
if isinstance(obj, datetime):
return obj.isoformat()
elif isinstance(obj, dict):
return {key: _json_serialize_datetime(value) for key, value in obj.items()}
elif isinstance(obj, list):
return [_json_serialize_datetime(item) for item in obj]
else:
return obj
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This _json_serialize_datetime helper function is a duplicate of the convert_datetime_to_iso function in backend/models/conversation.py and the _json_serialize_datetime function in backend/utils/webhooks.py. Please refactor this into a single, shared utility function in a common module to avoid code duplication and improve maintainability.

Comment thread backend/utils/webhooks.py
Comment on lines +22 to +31
def _json_serialize_datetime(obj: Any) -> Any:
"""Helper function to recursively convert datetime objects to ISO format strings for JSON serialization"""
if isinstance(obj, datetime):
return obj.isoformat()
elif isinstance(obj, dict):
return {key: _json_serialize_datetime(value) for key, value in obj.items()}
elif isinstance(obj, list):
return [_json_serialize_datetime(item) for item in obj]
else:
return obj
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This _json_serialize_datetime helper function is a duplicate of the convert_datetime_to_iso function in backend/models/conversation.py and the _json_serialize_datetime function in backend/utils/app_integrations.py. Please refactor this into a single, shared utility function in a common module to avoid code duplication and improve maintainability.

Comment thread backend/utils/webhooks.py
webhook_url += f'?uid={uid}'
try:
payload = memory.as_dict_cleaned_dates()
payload = _json_serialize_datetime(payload)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The memory.as_dict_cleaned_dates() method already recursively converts all datetime objects within the conversation dictionary to ISO format strings. Therefore, calling _json_serialize_datetime(payload) on its output is redundant and adds unnecessary processing. You can remove this line.

Suggested change
payload = _json_serialize_datetime(payload)
payload = memory.as_dict_cleaned_dates()

Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant