Skip to content

Use FastAPI validation tricks #10

@hbusul

Description

@hbusul

In backend/apps/task/semester_routers.py, line 42 we have

  if (
        semester["dLesson"] < 0
        or semester["dBreak"] < 0
        or semester["slotCount"] < 3
        or semester["slotCount"] > 15
    ):

We should always validate user inputs before we process them. But it might be cleaner to do it using FastAPI features.
Here is the page describing validating body fields.
So instead of validating things in the function, we can validate things in the model and delegate FastAPI to do that.

In the model, it might be something like

dLesson: int = Field(..., gt=0)

They also mention the same tricks apply to query and path parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions