#13314: "FIleField" validation does not account for "upload_to" when counting
characters
---------------------------+------------------------------------------------
Reporter: denilsonsa | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.1
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
I have a model with a FileField object:
{{{
def set_file (instance, filename):
return os.path.join("uploaded_files/my_obj_%d" % instance.my_obj_id,
os.path.basename(filename))
class MyModel(models.Model):
my_file = models.FileField(upload_to=set_file, null=True)
}}}
And I have a view that receives the POST and handles it to a trivial
forms.ModelForm object. In that view I check for .is_valid().
Since the FileField creates a 100-char column at the database, any
filename greater than 100 chars will be rejected, and the form instance
will have a nice error message talking about this.
However, this comparison is broken, because the actual data stored at the
database won't be the filename, but instead the return value of the
"upload_to" callable. This returned value, in my case, has more characters
than the actual filename.
Thus, in this case, filenames between 75 and 100 characters will be
accepted by the form validation, but will be rejected by the database when
the actual .save() occurs.
I'm not very sure about what is the best solution, but the
forms.fields.FileField shouldn't rely just on the max_length parameter
when validating the input.
--
Ticket URL: <http://code.djangoproject.com/ticket/13314>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.