Skip to content

Fix: pydantic migrations error handling #786

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

Merged
merged 1 commit into from
May 15, 2025
Merged

Conversation

1yam
Copy link
Member

@1yam 1yam commented May 8, 2025

When re syncing a node some message is not valid anymore,
Those message just getting re try and failing, the goal of this PR is to catch those error and reject

Related Clickup or Jira tickets : ALEPH-XXX

Self proofreading checklist

  • Is my code clear enough and well documented
  • Are my files well typed
  • New translations have been added or updated if new strings have been introduced in the frontend
  • Database migrations file are included
  • Are there enough tests
  • Documentation has been included (for new feature)

Changes

This pull request addresses error handling improvements and dependency updates in the message processing pipeline. The changes ensure better handling of serialization issues and expand exception handling for validation errors.

Error Handling Improvements:

  • src/aleph/db/accessors/messages.py: Added a fix to ensure all values in the details dictionary are JSON serializable, converting exceptions (e.g., ValueError) to strings when necessary. This prevents potential errors during logging or serialization.

Dependency Updates:

Validation Error Handling:

  • src/aleph/schemas/pending_messages.py: Updated the parse_message function to catch both pydantic.ValidationError and pydantic_core.ValidationError, ensuring broader coverage for validation-related exceptions.

How to test

Explain how to test your PR.
Re sync a node

Print screen / video

Some message who got now rejected:

{
   "time":1574117628.065,
   "type":"POST",
   "chain":"NULS2",
   "sender":"NULSd6HgV6PB8e86EGg1LX1dK5zVqwnmHejb7",
   "channel":"MYALEPH",
   "item_hash":"6e887a519187182bd1222de80a9b214d4c6987de85b6836adc98c282fb712df5",
   "item_type":"inline",
   "signature":"G8OumEXfDCubJTFeyBsBRauM//W8MY9EwvJ2j8/OC0yGDixSmYQzJ0ol5rM1t2tf6dja0Wwp0AQfkwf/xDzs/P8=",
   "item_content":"{\"type\":\"amend\",\"address\":\"NULSd6HgV6PB8e86EGg1LX1dK5zVqwnmHejb7\",\"content\":{\"body\":\"\",\"title\":\"\"},\"time\":1574117628.065}"
}

Errors:

{
   "errors":[
      {
         "ctx":{
            "error":"A 'ref' is required for POST type 'amend'"
         },
         "loc":[
            "content",
            "type"
         ],
         "msg":"Value error, A 'ref' is required for POST type 'amend'",
         "url":"https://errors.pydantic.dev/2.11/v/value_error",
         "type":"value_error",
         "input":"amend"
      }
   ]
}

Notes

We might need to fully re sync a node and ensure no important message go rejected and shouldn't.

@nesitor nesitor merged commit c4a949c into main May 15, 2025
5 of 6 checks passed
@nesitor nesitor deleted the 1yam-fix-reject-message branch May 15, 2025 08:37
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.

2 participants