Skip to content

Tweak documentation of Field.exclude#7086

Merged
hramezani merged 1 commit intopydantic:mainfrom
Viicos:Viicos-patch-1
Aug 15, 2023
Merged

Tweak documentation of Field.exclude#7086
hramezani merged 1 commit intopydantic:mainfrom
Viicos:Viicos-patch-1

Conversation

@Viicos
Copy link
Copy Markdown
Member

@Viicos Viicos commented Aug 11, 2023

Change Summary

I don't know if this is expected, but doing the following:

from typing import Annotated, TypeVar

from pydantic import BaseModel, Field

T = TypeVar("T")

ExcludedField = Annotated[T, Field(exclude=True)]


class Model(BaseModel):
    run_path: ExcludedField[str | None] = None

Model.model_json_schema()
#> {'properties': {'run_path': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'default': None, 'title': 'Run Path'}}, 'title': 'Model', 'type': 'object'}
Model(run_path="a").model_dump()
#> {}

The field is still included in the JSON Schema. So either the docstring is incorrect or it should not be included in the JSON Schema as well?

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @adriangb

@Viicos
Copy link
Copy Markdown
Member Author

Viicos commented Aug 11, 2023

Please review

@hramezani hramezani merged commit 69357e1 into pydantic:main Aug 15, 2023
@hramezani
Copy link
Copy Markdown
Member

Thanks @Viicos

@Viicos Viicos deleted the Viicos-patch-1 branch August 15, 2023 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants