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

Pyright type issue with strawberry.file_uploads.Upload #3382

Open
axiomofjoy opened this issue Feb 15, 2024 · 4 comments
Open

Pyright type issue with strawberry.file_uploads.Upload #3382

axiomofjoy opened this issue Feb 15, 2024 · 4 comments

Comments

@axiomofjoy
Copy link

axiomofjoy commented Feb 15, 2024

Describe the Bug

VSCode and Pyright give me red squiggly lines when using strawberry.file_uploads.Upload.

Repro:

Save a file with the contents:

from strawberry.file_uploads import Upload


async def read(f: Upload) -> bytes:
    data = await f.read()
    return data

Then run pyright on this file. You will see something like

/Users/xander/memly/backend/scratch2.py
  /Users/xander/memly/backend/scratch2.py:5:5 - error: Type of "data" is unknown (reportUnknownVariableType)
  /Users/xander/memly/backend/scratch2.py:5:18 - error: Type of "read" is unknown (reportUnknownMemberType)
  /Users/xander/memly/backend/scratch2.py:5:20 - error: Cannot access member "read" for type "Upload"
    Member "read" is unknown (reportAttributeAccessIssue)
  /Users/xander/memly/backend/scratch2.py:6:12 - error: Return type is unknown (reportUnknownVariableType)
4 errors, 0 warnings, 0 informations

System Information

  • Operating system: MacOS
  • Strawberry version (if applicable): strawberry-graphql==0.219.2

Additional Context

Screenshot 2024-02-14 at 11 13 05 PM

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@axiomofjoy axiomofjoy added the bug Something isn't working label Feb 15, 2024
@axiomofjoy
Copy link
Author

I'm running strict mode. It looks like that's not currently supported. Any plans to support?

@furrukh-asif
Copy link

Any update here? Running into this issue in Pyright basic mode as well.

@bellini666
Copy link
Member

This issue is happening because Upload is defined as a NewType of bytes, meaning that it indeed doesn't have those methods.

To solve that issue you can do what is described at the end of this section of the docs: https://strawberry.rocks/docs/guides/file-upload#upload-scalar . i.e. use the upload type for your framework, and define a scalar override for it.

Please let me know if that solves the issue and or if we need to change something in the documentation to make it more clear :)

@bellini666 bellini666 added documentation and removed bug Something isn't working labels Dec 18, 2024
@axiomofjoy
Copy link
Author

I see, thanks. I moved off of pyright, please feel free to close the issue if it is user error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants