tortoise / tortoise/tortoise-orm

pydantic_model_creator not validates JSONField

Open
#1,251 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

when creating a pedantic model with pydantic_model_creator, the JSON fields are not enforced and validated on pedantic.

I found in the source code https://github.com/tortoise/tortoise-orm/blob/4a81c051d2d8082839a8f15b0f332220e753ea27/tortoise/contrib/pydantic/creator.py#L402 that it specifies type of Any instead of pydantic.Json[Any]

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 in tortoise/contrib/pydantic/creator.py around line 402, where JSONField is assigned its generated type. Reproduce pydantic_model_creator with a JSONField and add coverage showing invalid JSON data is rejected; done means the generated model validates that field instead of accepting any value.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.