-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Ability to include private or "_" fields as part of the model. #1388
Labels
Comments
Duplicate of #655. |
With MongoDB, which has an from pydantic import BaseModel, Field
class MongoResponse(BaseModel):
id: str = Field(..., alias="_id")
class Config:
allow_population_by_field_name = True
response = MongoResponse(_id="ThisIsAnId")
print(response.dict()) Output:
So with your example: from pydantic import BaseModel, Field
class ElasticsearchRequest(BaseModel):
source: dict = Field(..., alias="_source")
class Config:
allow_population_by_field_name = True
request = ElasticsearchRequest(_source={'include': ['text']})
print(request.dict())
print(request.dict(by_alias=True)) Output:
|
@StephenBrown2 how can i use the |
Instead of using id: str = Field(None, alias="_id") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Request
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:When building models that are meant to add typing and validation to 3rd part APIs (in this case Elasticsearch) sometimes field names are prefixed with
_
however these are not private fields that should be ignored and users may want them included in the model.Output:
The text was updated successfully, but these errors were encountered: