On Sat, Feb 13, 2010 at 12:09 AM, Gleber <glebi...@gmail.com> wrote: > I don't know if this is a bug.. Here is the minimal test case: > > class CustomStorage(FileSystemStorage): > def get_valid_name(self, name): > import random > return '%s.abc' % (random.randint(100, 999),) > > def test_uploadto(self,filename): > return 'aaa/%s' % filename > > testA = models.FileField(storage=CustomStorage(), upload_to='test') > testB = models.FileField(storage=CustomStorage(), > upload_to=test_uploadto) > > In testA, the file will be saved like "test/123.abc" (as expected) > > In testB, the file will be saved like "aaa/FILENAME", where FILENAME > is the name of the local file uploaded by the user, but at least for > me, is expected that the argument filename is generated by the storage > as in the testA.. > > If you specify a callable upload_to, then that is the routine that is used to generate the file name, replacing entirely the default name-generating routine that would ordinarily combine the specified upload_to directory with the result of calling the storage get_valid_name(). I'm not sure if that is a bug or not.
>From one point of view you could say no, that the upload_to implementation is responsible for calling the storage get_valid_name to ensure whatever name it wants is valid on the storage backend. So your upload_to should, instead of using filename directly, run it through self.storage.get_valid_name and use the result of that to generate the full upload path+name. On the other hand that's not a requirement that appears to be documented anywhere, and I'm not sure it's a reasonable requirement. It's probably worth opening a ticket to either document that callable upload_to routines should be doing this or change things to ensure that the storage get_valid_name is always called. The problem with the latter is we've then got two different sources for names: callable upload_to and the storage backend, both of which can ignore the name they are given and return something else entirely. Whichever one is called last will 'win', and it isn't clear which one that should be. Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.