-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
From future import annotations breaks lazy types #3568
Comments
Update: was able to reproduce with the following code
from __future__ import annotations
from typing import TYPE_CHECKING, Annotated
import strawberry
if TYPE_CHECKING:
from .user import User
LazyUser = Annotated["User", strawberry.lazy(".user")]
@strawberry.type
class Post:
user: LazyUser
from typing import TYPE_CHECKING, Annotated
import strawberry
if TYPE_CHECKING:
from .post import Post
@strawberry.type
class User:
posts: list[Annotated["Post", strawberry.lazy(".post")]] Failes with: Traceback
If we remove |
I seem to get a similar result when attempting to use
Sample code:
Considering that the PEP behind |
That's not the case fortunately 😊 But we should probably find a way to make it work any way 🤔 |
Oh, it does indeed seem like it. I might give this a go (though i have no experience with this stuff) sometime in the future if nobody takes it up |
Seems like this behaviour of forwardref becomes default in python 3.14: https://docs.python.org/3.14/whatsnew/3.14.html |
Since I've touched this earlier, I'll try to tackle this during the following couple of weeks! |
I was trying to reproduce this with a code similar to yours @dartt0n , but it always "works for me". I'll try a bit more, but in the mean time, can you tell me which version of python were you using to reproduce this? |
Describe the Bug
from __future__ import annotations
breaks type resolver which results inTypeError: Model fields cannot be resolved. Unexpected type 'typing.Any'
I did not manage to track down what exactly causes this issue, but whenever I add
from __future__ import annotations
to the top of the file with strawberry types - strawberry type resolver breaksSystem Information
Additional Context
Upvote & Fund
The text was updated successfully, but these errors were encountered: