Code

Opened 4 years ago

Last modified 3 days ago

#14787 assigned New feature

Upload handler should pass errors on to forms.FileField

Reported by: intgr Owned by: anubhav9042
Component: File uploads/storage Version: master
Severity: Normal Keywords:
Cc: anubhav9042@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As far as I can tell, currently no mechanism exists for file upload handlers to pass errors forward to form fields.

The result is that any upload errors result in "This field is required" or "The submitted file is empty" messages.

Other errors worth handling:

  • File upload size limits
  • Unicode decode error in filename

Thoughts?

Attachments (1)

14787.diff (2.3 KB) - added by anubhav9042 3 days ago.
max_size for FileField

Download all attachments as: .zip

Change History (18)

comment:1 Changed 4 years ago by gabrielhurley

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This seems reasonable to me and I don't see any obvious mechanism in place with which to do this currently. Marking accepted.

comment:2 Changed 3 years ago by anonymous

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 4 months ago by anubhav9042

  • Cc anubhav9042@… added
  • Owner changed from nobody to anubhav9042
  • Status changed from new to assigned

There have been some changes since past years. But I am in favour of this.
I hope/intend to do this in GSoC this year. I think the following can also be added along with those suggested above:

File not uploaded completely
Write failure

comment:6 Changed 3 weeks ago by anubhav9042

  • Version changed from 1.2 to master

comment:7 Changed 3 weeks ago by anubhav9042

for upload limit we now have max_length.
We can have a check unicode error in filename and also of possible the two I mentioned above.

EDITS: max_length error is for filename.

Last edited 4 days ago by anubhav9042 (previous) (diff)

comment:8 Changed 5 days ago by timo

In general we should be careful about exposing detailed error messages to users. e.g. I believe the unicode error is a server configuration issue (see #17686). Similarly, "file not uploaded completely" and "write error" are not issues that the user is in a position to resolve so if anything, those errors would need to be surfaced as something like "The file upload was unsuccessful. Contact the site admin if the error persists". The issue of upload size seems like a valid one though. Do you have a proposal for propagating errors from upload handlers to forms?

comment:9 Changed 4 days ago by anubhav9042

I think checks for exceeding_upload_size and for encoding_type, we could add a check in forms.FileField.to_python(). We already have several checks there, so it seems reasonable enough to add there.
Thought on this?

Changed 3 days ago by anubhav9042

max_size for FileField

comment:10 Changed 3 days ago by timo

Although the scope of this ticket isn't well defined, I think what you've implemented is somewhat tangential to what the summary describes "Upload handler should pass errors on to forms.FileField" -- although, I'm not sure how/if file size limit errors would be part of the upload handler. Btw, max_upload_size already exists as a third party package: django-validated-file. We'd probably want a mailing list thread to figure out if we'd want to bring it into core. I don't feel strongly either way on doing so.

comment:12 Changed 3 days ago by timo

A couple comments on the post:

  1. It's better to make a proposal than ask "what to do" or "how to solve a ticket." What do you think should be done? If you don't care, then find I'd find something else to work on.
  1. A subject that includes a description of the item instead of "Decision for ticket #14787" is more likely to get interested people to read it.

comment:13 Changed 3 days ago by anubhav9042

I did mention what I want to do, i.e. including the new attribute max_size, though I will pay more attention to the subject from next time onwards.
Thanks.

comment:14 Changed 3 days ago by timo

What's the file name encoding issue you mentioned in the mailing list post? Is it different from #17686?

comment:15 Changed 3 days ago by anubhav9042

What I wanted to say is we can inform the user about the problem in a better way than just adding in the docs by raising a proper error in to_python() itself as we have file_name there so we could check the encoding.

comment:16 Changed 3 days ago by timo

It's a server configuration issue that should be fixed by the person deploying the site, not something an end user should get an error about.

comment:17 Changed 3 days ago by anubhav9042

OK. So we are down to that maximum size issue itself.
Can you please post your replies on both the points on ML, so that when someone sees he knows about these things as well.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from anubhav9042 to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.