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
The flag allow_population_by_field_name is not recognized #38
Comments
Well, I wouldn't expect this to work - it doesn't exist :). Also, not in the docsö. What is this flag supposed to achieve exactly? |
The flag gives the Model the ability to accept the data in both the field name and the alias. so you can do: data = {
"body": "lorem ipsum ..."
"author": {
"login": "username",
...
}
}
obj = Review(**data) same as: data = {
"body": "lorem ipsum ..."
"user": {
"login": "username",
...
}
}
obj = Review(**data) |
oh, you mean the pydantic config. I see. So, this library doesn't read the pydantic model config, but rather the configuration of individual fields. I'm not sure how desirable this behaviour is - @lindycoder , thoughts? @islam-main how would you suggest implementing this? |
Yes i'm missing this behaviour actually, wanted to propose an update but i'm short on time. Would default to True for backward compatibility That new config would turn off this
|
Ok. Then a PR is welcome here 😃. I'll add the label. |
@sondrelg @Goldziher Why wouldn't we support both (name and alias) and implement the same behavior of Pydantic itself? |
It's true that if you try to make the factory work on field name but the model doesn't have the flag then it will fail. That's a good argument for reading the model's config. |
Implementation should support both I guess. I mean, both the field name and alias. |
I am also short on time but I think I might be able to open a PR in a week or something to initiate Pydantic Model Config support. |
I'll start with this issue flag |
@islam-main @Goldziher #43 this is it? I have the same issues. If this PR looks fine, I would be glad to merge it as soon as possible |
@mrkovalchuk Yes it's, I'll check it. |
Thank you for contributing. There are comments on the PR. |
Thanks a lot for contributing @mrkovalchuk - v1.2.9 is been released with your contribution. |
I have two models
User
,Review
and theirModelFactory
s.*note: all assertion are successful
Review
model has theallow_population_by_field_name
flag set toTrue
which meansReview
model should be able to accept bothauthor
anduser
attributes topopulate the
User
model, however it's not recognized on building the instance andnew instance gets created.
I also noticed that new object was created on supplying a valid
User
instance to theReviewFactory
!!see the
why
lineThe text was updated successfully, but these errors were encountered: