On Thu, Apr 2, 2009 at 12:33 PM, Marty Alchin <gulop...@gmail.com> wrote:

>
>
A related, thus-far-unreported (I think) issue comes up when
> attempting to access width_field and height_field attributes on a
> model prior to saving the new file.
>

Actually it looks like this was kinda reported, it just wasn't recognized as
related to r9766:

http://code.djangoproject.com/ticket/10404

And the problem is slightly worse than just being unable to access the
fields prior to saving: turns out if the fields are declared before the
associated image field in the model, they aren't set properly at all.

We've now got unresolved:

#10249 - MRO exception on attempt to assign File to FileField
#10300 - Storage backend cannot get length of content
#10404 - Image width/height fields not set properly

plus the file name issue (pre-save signal handler does not get actual file
name) that started this thread, which I don't believe has a ticket.

There are tentative patches for the first two (plus Marty you say you have
some ideas how to fix them, but I'm not sure how those ideas differ from
what's noted in the tickets).  #10404 seems fixable as well given a bit of
thought.  But I really don't know what to do about the file name issue.

We cannot know for sure what the file name is until it is saved to disk, as
the save operation may tack on underscores when handling race conditions.
Thus we cannot delay file save to a field pre_save routine and report the
guaranteed correct file name in a pre_save signal handler, since the latter
runs before the former.  In fact, there may be code out there expecting to
know the correct name much earlier than a pre-save signal.  For example:

form = ModelFormForModelContainingFileField(request.POST, request.FILES)
if form.is_valid():
    m = form.save(commit=False) # this actually saved the file to disk
pre-9766
    # ... code that uses the FileField's assigned file name ...

works on 1.0.X but will run into trouble post-r9766 as the file won't be
saved anymore as part of the form.save(commit=False).  I can easily cause
some of our existing model_forms tests to fail due to reported file name
differences by passing commit=False on form save.  Making the same
commit=False additions pre-9766 does not cause the failures, as pre-r9766
the file was saved and the name was set during form save regardless of the
commit argument.

I don't see how we can support knowing the actual  file name as early as we
used to and simultaneously delay saving the file long enough so that model
validation doesn't cause file data to be written to disk...though I don't
know enough about the model validation implementation to understand exactly
why it was triggering the write-to-disk, as in the code above it's happening
during a form-specific save routine and a form wouldn't necessarily be
involved in model validation.

I feel like I'm going around in circles thinking about this one -- is there
a way out that someone else sees that I'm blind to?

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to