thunderbird / thunderbird/appointment

Simplify pydantic validation errors

Open
#270 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
552
Forks
29
Avg merge
1d 6h
Merged PRs (30d)
23

Description

We don't really do a lot of form data validation mostly because everything is just loosey goosey text fields. But as we tighten things up a little more we should look into overriding the default pydantic/fastapi validation exception to be localized, and simplified. We can pretty easily override the exception class (https://stackoverflow.com/a/62937832).

Here's an example of what it looks like now:

{
  detail: [{
      type: 'greater_than_equal',
      loc: ['body', 'slot_duration'],
      msg: 'Input should be greater than or equal to 10',
      input: 5,
      ctx: { ge: 10 },
      url: 'https://errors.pydantic.dev/2.5/v/greater_than_equal',
    }],
}

On the backend we should grab the approriate values (like type, context, input, field name (loc[1])) and generate a localized error message. We'll also have to add some extra meta data to include things like field units (like minutes for slot_duration for example.) We don't have to do every possible variation of error just the ones we use. Moving forward if we use a new type of field validation, we'll make sure to cover that in the PR.

Here's some useful info on pydantic's error messages.
https://docs.pydantic.dev/latest/errors/errors/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the backend's current Pydantic/FastAPI validation exception handling and the linked Pydantic error documentation. Done means the supported validation cases return simplified, localized messages using field names, context, inputs, and relevant metadata such as slot-duration units, with coverage for the validation types currently used.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend, internationalization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.