-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Attribute error for functools.partial
#5101
Comments
Thanks @JensHeinrich for reporting this issue. I can confirm the issue. it may fix by accessing the function in the following line. I mean replacing pydantic/pydantic/_internal/_decorators.py Line 204 in 73373c3
Would you like to open a PR? |
I am already working on a PR, but at the moment I just add a better error |
This fixes pydantic#5101 atleast in regards to the unhelpful message As this check is only done on creation of a class the overhead should be ok
Even if the |
Also signature creation doesn't work on it |
This one also can be fixed by the same change that I mentioned before.
I think we can make it work at least on @samuelcolvin Do you think we should prevent using |
TBH I feel |
agreed. Feel free to create an issue on cpython and copy me into it, I'd be interest to see what they say. Also, can you create a PR against main to see if this is working there? |
This one can be related https://bugs.python.org/issue34475 |
I created an issue python/cpython#102323 |
I personally find the responses in the links from the last two comments reasonable; it seems we should just not assume that |
I'm good with using a default value instead, too. |
I am working on a PR for v1.10 already |
I would only allow those with |
Was suggested in python/cpython#102323 by @sobolevn. Fixes pydantic#5101 Superceedes pydantic#5102
(responded on the PR; overall I am fine with the change) |
* Use getattr and default for qualname Was suggested in python/cpython#102323 by @sobolevn. Fixes #5101 Superceedes #5102 * Import tests from #5102 * Fix signature generation for functools * Use getattr and default for name * Remove expectation of error from tests * Reset tracked validators * Describe changes * Use getattr and default for module * Use id as fallback * Tweak name formatting --------- Co-authored-by: JensHeinrich <github.com/JensHeinrich> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
This was solved in #5362 for V2. |
Initial Checks
Description
Using a
partialmethod
orpartial
as avalidator
orroot_validator
creates an unhelpfulAttributeError
:The problem is rooted at this code.
IMO an try except block with a test for partial methods would be useful here, telling the User to supply the "allow_reuse" parameter for partials.
Example Code
Python, Pydantic & OS Version
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: