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
Union does not work with GenericModel #3276
Comments
It seems the problem is in this part of lenient_subclass.
If we remove this isinstance check, and just return False, the old behaviour comes back, and all the tests still pass, from my understanding the |
We don't have For that reason, I'll be closing the issue. 🙏 |
I don't think this issue was specific to generic models (you didn't actually use the typevar in your model anyway), but either way, in v2, it seems to be fixed (noting that you just use BaseModel directly in v2, instead of GenericModel): from typing import Union, TypeVar, Generic
from pydantic import BaseModel
T = TypeVar("T")
class Request(BaseModel, Generic[T]):
url: str
data: Union[str, bytes, None] = None
class PostData(Request[str]):
url: str = "https://httpbin.org/anything"
data: str = "rand data" No error is raised when you run the code above |
Cool! Thanks, will be playing around with v2 soon :) |
Checks
Bug
I've been toying with the master branch since autocomplete support got merged and seems like there is a regression since
1.8.2
.Consider this example:
With pydantic
1.8.2
it produces such output:Which is ok, all I have to do is specify
data
type:But with latest commit on
master
branch it yields a different error:Any ideas? :)
The text was updated successfully, but these errors were encountered: