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

Warn and ignore __slots__ argument to create_model #4432

Merged
merged 5 commits into from Aug 24, 2022

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Aug 24, 2022

Found while investigating error in litestar-org/litestar#401

Change Summary

In v1.9.2 __slots__ could be passed to create_model, I'm not sure if it was honoured or ignored, but it didn't cause an error.

In v1.10.0a2 however it caused a warning, and if that warning was ignored, an error creating the model.

This was happening here

Even more unusually, this only seemed to be an error if pydantic is compiled.

With this change a RuntimeWarning is raised, and __slots__ is then ignored.

Related issue number

Caused by #3946 I think.

@samuelcolvin
Copy link
Member Author

please review.

@samuelcolvin samuelcolvin changed the title Create model slots Warn and ignore __slots__ argument to create_model Aug 24, 2022
@hramezani
Copy link
Member

Except the failing CI, LGTM 👍

@samuelcolvin
Copy link
Member Author

I'll wait for @hot123s (author of #3946) and @PrettyWood to review, then I think we're ready for a final pre-release - v1.10.0b1.

Comment on lines +341 to +343
# With python 3.8, specifically 3.8.10, Literal "is" check sare very flakey
# can change on very subtle changes like use of types in other modules,
# hopefully this check avoids that issue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to know what is compiled behind the scene to understand how this edge case arrives. Such a weird bug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, so weird.

The line that caused the issue again was __slots__: Optional[Tuple[str, ...]] = None,, if I changed it to __slots__: 'Optional[Tuple[str, ...]]' = None, it went again. But I decided this was a safer fix.

@samuelcolvin
Copy link
Member Author

okay, I want to get the (hopefully) last pre-release out, so I'm going to merge this.

@samuelcolvin samuelcolvin merged commit 0244b06 into main Aug 24, 2022
@samuelcolvin samuelcolvin deleted the create_model-slots branch August 24, 2022 19:13
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