Skip to content
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

[BUG] Field serialized when using repr=False #1269

Open
robinsandstrom opened this issue Aug 19, 2024 · 1 comment
Open

[BUG] Field serialized when using repr=False #1269

robinsandstrom opened this issue Aug 19, 2024 · 1 comment

Comments

@robinsandstrom
Copy link

Fields are still included when using repr=False. Look at the following example:

Expected behaviour is to have fields with repr=False to not serialize, or am I missing something? :)

from pydantic import BaseModel, Field
from ninja import Schema

class ModelExample(BaseModel):
    height: int
    width: int
    area: int = Field(repr=False)
    ### or  
 
    @computed_field(repr=False)
    @cached_property
    def area(self) -> int:
        return  height*width

class OutSchema(ModelExample, Schema):
     pass

Versions (please complete the following information):

  • Python version: 3.12
  • Django version: 5.01
  • Django-Ninja version: 1.2.x
  • Pydantic version: 2.x
@vitalik
Copy link
Owner

vitalik commented Aug 20, 2024

@robinsandstrom

repr is used for representation (in console) - see docs

basically that means that when you do this:

>>> x = ModelExample(...)
>>>  x
<ModelExample height=1 width=2>
# ^ no area in repr

what you probably need is exclude - see docs

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

No branches or pull requests

2 participants