tortoise / tortoise/tortoise-orm

pydantic v2,computed cannot use attribute from exclude

Open
#1,464 3 comments 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

modify from example:
https://github.com/tortoise/tortoise-orm/blob/develop/examples/fastapi/models.py
show full_name and hide name:

    class PydanticMeta:
        computed = ["full_name"]
        exclude = ["password_hash","name"]
raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')

AttributeError: 'User' object has no attribute 'name'

Describe the bug
tortoise-orm: v0.20.0
pydantic : v2.3.0

Expected behavior
like pydantic v1, computed first then exclude

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 with examples/fastapi/models.py and reproduce the Pydantic v2 case where User computes full_name while name is excluded. Trace the serialization order that produces the AttributeError, then verify that the computed field works while name remains hidden and compare the behavior with the stated Pydantic v1 expectation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.