strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
420 stars 122 forks source link

When the optional file field is used, an error will be reported when there are empty files in the query set #545

Open Eraldo opened 5 months ago

Eraldo commented 5 months ago

Describe the Bug

Current: FileField with blank=True gets resolved as required by auto! Expected: FileField with blank=True gets resolved as optional by auto.

As a temporary workaround I overwrite them explicitly on my type if they are supposed to allow being optional: asset: FileType | None

Error is thrown from here https://github.com/django/django/blob/475cffd1d64c690cdad16ede4d5e81985738ceb4/django/db/models/fields/files.py#L40

System Information

Additional Context

The issue has previously been reported, however the ticket owner closed it for a reason unknown to me. Ref: https://github.com/strawberry-graphql/strawberry-django/issues/58

Upvote & Fund

Fund with Polar

bellini666 commented 5 months ago

blank actually doesn't define a field as "nullable", what does is null

But having said that, we do have an issue with FileField/ImageField that we need to fix. More specifically, if the field is not set it will still return the field descriptor instead of None.

I'll use this issue as a marker for that