strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
MIT License
391 stars 115 forks source link

File field with blank=False fails validation in create mutation #468

Closed yergom closed 4 months ago

yergom commented 5 months ago

Follow up from #461. The PR https://github.com/strawberry-graphql/strawberry-graphql-django/pull/464 has solved saving the instance, but the validation code is still incorrect. FileFields with blank=False will fail validation.

Upvote & Fund

Fund with Polar

bellini666 commented 5 months ago

Hi @yergom ,

You mean, a field with blank=False should fail the validation if no file upload has been provided to it?

yergom commented 5 months ago

Hi @bellini666, no, that's not the case. Let me elaborate.

If you have a field with a non optional file

class MyModel(models.Model):
   file = models.FileField(null=False, blank=False)

then the validation fails. The problem is that the prepare_create_update method is not setting the file field in the dummy instance.

sdobbelaere commented 5 months ago

That's an interesting observation @yergom. I seem to remember that I refactored the update and create methodes with prepare_create_update. This was done in order to ensure that creates and updates would respect the manager configurations.

@bellini666 I've added a PR with some tests that should cover this issue. https://github.com/strawberry-graphql/strawberry-graphql-django/pull/469