Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Reworkcreate_model
field definitions format#11032
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
cloudflare-workers-and-pagesbot commentedDec 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | a0c253b |
Status: | ✅ Deploy successful! |
Preview URL: | https://ba5c77de.pydantic-docs.pages.dev |
Branch Preview URL: | https://create-model-rework.pydantic-docs.pages.dev |
If the value is a two-tuple, the first element is the type andthe second element is the assigned value (either a default ora `Field()` function). This isn't breaking as this was alreadyallowed before.We now also allow a single element to be passed, which will bethe type. This also isn't breaking because:- We previously allowed a single element to be passed if it was an annotated type. We then extracted the first metadata element and enforced it to be a `Field()` function. With these changes, we now just leave the annotated type as is, so an arbitrary amount of metadata can now be specified.- If the type wasn't annotated, we were raising an error.Private fields are now allowed.Redundant tests were merged/removed. Documentation was updated.The `__slots__` parameter was removed. It was deprecated (witha wrong warning class, but still) since 1.10, was not doing anything,so I don't expect anyone to be using it.
codspeed-hqbot commentedDec 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#11032 willnot alter performanceComparing Summary
|
github-actionsbot commentedDec 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
Seems like a common error was to write tests in this file,because it was named `test_create_model.py`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks@Viicos, solid improvement here.
Nice work with the docs updates. Also, pretty simple implementation change, which is nice as well.
A few follow up questions, but otherwise, looking great!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
I've added the As you mentioned, deprecated long ago, so I'm not too worried about breakages here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice work, excited to have this be more flexible.
c409bc7
intomainUh oh!
There was an error while loading.Please reload this page.
With recent release in pydantic, the pickling is not working asexpected. This restricts the pydantic to 2.10.6 untill we fix thebreaking changes.Relevant links:-https://github.com/pydantic/pydantic/releases/tag/v2.11.0-pydantic/pydantic#11032-https://iterativeai.slack.com/archives/C04A9RWEZBN/p1743143098907759
With recent release in pydantic, the pickling is not working asexpected. This restricts the pydantic to 2.10.6 untill we fix thebreaking changes.Relevant links:-https://github.com/pydantic/pydantic/releases/tag/v2.11.0-pydantic/pydantic#11032-https://iterativeai.slack.com/archives/C04A9RWEZBN/p1743143098907759
I'm look at this as I suspect this causes multiple regressions 2.10.6 -> 2.11.0 when using create_model known to me:
as there is multiple issues linked to this change - any chance this gets revisited? |
Viicos commentedApr 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
As mentioned in the linked issues, this wasn't documented/expected, in particular for |
Viicos commentedApr 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
At the very least, we could backport the fix for#11709 in the next patch release. |
commonism commentedApr 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Let's forget about model_config/config, inconvenient but won't cause any long lasting headaches. For computed fields and properties, as it works for models created by inheriting from BaseModel, there is nothing wrong in the expectation create_model can do the same. And it did the same for about two years. As an MRE for property issue: frompydanticimportcreate_model,ConfigDictdefmkx():defget_additionalProperties(x):returnx.model_extrareturnget_additionalProperties,None,NoneA=create_model('A',__config__=ConfigDict(extra="allow"),aio3_additionalProperties=(None,property(mkx()[0])),)a=A(x=1)assertnotisinstance(a.aio3_additionalProperties,property) A possible fix - make the annotation declaration optional: Lines 1742 to 1746 in2e7cddb
iff_def[0]:annotations[f_name]=f_def[0]fields[f_name]=f_def[1]else:annotations[f_name]=f_def |
There is, as I mention and this can be seen in the 2.10 documentation: We haven't decided on a solution yet, but it will probably not be using the |
Uh oh!
There was an error while loading.Please reload this page.
Fixes#11005,fixes#11015,closes#11006.
If the value is a two-tuple, the first element is the type and the second element is the assigned value (either a default or a
Field()
function). This isn't breaking as this was already allowed before.We now also allow a single element to be passed, which will be the type. This also isn't breaking because:
Field()
function. With these changes, we now just leave the annotated type as is, so an arbitrary amount of metadata can now be specified.Private fields are now allowed.
Redundant tests were merged/removed. Documentation was updated.
The
__slots__
parameter was removed. It was deprecated (with a wrong warning class, but still) since 1.10, was not doing anything, so I don't expect anyone to be using it.Change Summary
Related issue number
Checklist