Fix a crash when cleaning the namespace in ModelMetaclass#10242
Conversation
This happens when `MotelMetaclass` is used as a metaclass for a class other than `BaseModel`.
Deploying pydantic-docs with
|
| Latest commit: |
79ffa7c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d1d89a9d.pydantic-docs.pages.dev |
| Branch Preview URL: | https://metaclass-fix.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10242 will not alter performanceComparing Summary
|
samuelcolvin
left a comment
There was a problem hiding this comment.
Can you add a test, even if it's weird and specific.
| for instance_slot in '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__': | ||
| del namespace[instance_slot] | ||
| if instance_slot in namespace: # Safe check in case the metaclass is used other than in `BaseModel`: | ||
| del namespace[instance_slot] |
There was a problem hiding this comment.
Surely, nameapace.pop(instance_slot, None) is better - only one lookup of the dict.
sydney-runkle
left a comment
There was a problem hiding this comment.
Thanks for the quick fix here!
In the future, let's break PRs like #10110 up into two - simple annotation order switches to adhere to type checker rules, and separately, actual code changes.
Well in this case the two were required to work together. |
|
Ah I see, fair enough. And the diff was small enough on the PR that things weren't too difficult to track down. |
This happens when
MotelMetaclassis used as a metaclass for a class other thanBaseModel.Fixes #10239
Change Summary
Related issue number
Checklist