-
Notifications
You must be signed in to change notification settings - Fork 35
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
UploadedFileInput Error when modifying or deleting model #151
Comments
When modifying the model and changing the image, the error does not occur. This appears to be an issue when editing the model but not adding or changing the image. |
Here is an example implementing this: https://django-formset.fly.dev/bootstrap/person (it's contained in the supplied demos of this project). Maybe I didn't understand your question. |
The test app includes the create workflow for creating a Person with an image. The issue occurs on the update and delete workflows. update only works if you reattach the image, submitting with the existing image raises the No file was submitted. Check the encoding type on the form error. delete also does the same. In summary, the error occurs when a model is loaded with an image and a form is displayed with the model instance, the form is updated but the image or file field is left unchanged, and then the form is submitted. The error occurs in validation, prior to the form_valid method being called |
After a lot of debugging. To stop this from occurring, if you are loading and updating an Image field, you must use the FileField field from formset.fields. This has an overridden clean method. If you use the default field for models.FileField or models.ImageField then the field is incorrectly marked as changed in the form, which causes the error. Example
Note, you don't have to specify the widget as this is specified in FileField. This may require an update to the documentation to make it clearer. |
Now I see what might be the problem. Does your django-formset/formset/utils.py Line 168 in e72e58c
|
When using the UploadedFileInput.On creation, uploaded image is stored successfully, however when modifying the model but not changing the image, or when deleting the model, the following validation error is shown: No file was submitted. Check the encoding type on the form.
The form
The model
When debugging, the FormViews form_valid method is not reached.
The text was updated successfully, but these errors were encountered: