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

Tweak documentation of Field.exclude #7086

Merged
merged 1 commit into from Aug 15, 2023
Merged

Conversation

Viicos
Copy link
Contributor

@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
Contributor Author

Viicos commented Aug 11, 2023

Please review

@hramezani hramezani merged commit 69357e1 into pydantic:main Aug 15, 2023
48 checks passed
@hramezani
Copy link
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.

None yet

3 participants