On Thu, Apr 2, 2009 at 8:59 AM, Lior Gradstein <lior.gradst...@gmail.com>wrote:
> > I noticed an important change in behaviour between Django 1.0.2 and > Django 1.1+ (svn and beta versions). > > If I set a signal that intercepts as pre_save and try to access a > FileField/ImageField's path, I don't get the same result. It seems the > 'upload_to' attribute is not taken into account! > It seems to be set much later, compared to version 1.0.2. Is this a > feature or a bug? > I think it's a bug, and I'm pretty sure it was introduced by r9766. The setting of the actual file name that will be used (which pulls in the upload_to path and possibly tacks on some underscores if the uploaded name conflicts with already-present file(s) in the upload directory) is done by django.db.models.fields.files.FieldFile save(). This used to be called fairly early on from the django.db.models.fields.files.FileField save_form_data() method but r9766 moved that to much later, namely a newly-introduced pre_save() routine in FileField. Since (from a brief look at django.db.models.base.Model save_base()) the field pre_save routine is called after the pre_save signal is sent, the real file name has now not yet been set when the pre_save signal is sent. There are a couple of still-open tickets for other side-effects of r9766 (#10249, #10300) but I don't believe either of the potential fixes for those would fix this issue, so this probably needs a ticket with the details you provided (an integrated testcase would be even better, though I don't know how much signal testing is done by the test suite). Not sure what the right fix would be -- can just the setting of the name be pulled out of save() and done earlier by save_form_data()? Possibly save() would have to also still ensure it's done, in cases where save_form_data() is not involved? Can anyone with a better handle on r9766 comment on this (and #10249, #10300)? Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---