Opened 17 years ago
Closed 9 years ago
#5619 closed Bug (invalid)
FileField and ImageField return the wrong path/url before calling save_FOO_file()
Reported by: | Owned by: | Leah Culver | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Someday/Maybe | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Models with FileField or ImageField attributes do not function properly. The get_FOO_filename() and get_FOO_url() methods fail to insert the upload_to path if they are accessed before a call to save_FOO_image(). This happens because _get_FIELD_filename() and _get_FIELD_url() do not call field.get_filename(). I've attached a patch to resolve the issue.
Attachments (2)
Change History (27)
by , 17 years ago
Attachment: | get_filename_fix.diff added |
---|
comment:1 by , 17 years ago
Needs tests: | set |
---|
comment:2 by , 17 years ago
Keywords: | fs-rf added |
---|
comment:3 by , 17 years ago
Keywords: | fs-rf-fixed added; fs-rf removed |
---|
comment:4 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 17 years ago
milestone: | → 1.0 beta |
---|
comment:6 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 16 years ago
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:10 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
This patch is totally broken, and breaks get_FIELD_url for all files or images uploaded prior to the current day, because field.get_directory_name uses datetime.now() to interpolate the date values. [7986] needs to be reverted as soon as possible.
comment:11 by , 16 years ago
You do know you can get your own copy reverted back to pre-7986 by doing something like:
svn -r7985 up
right? So you can get your code back to working immediately without the change actually being reverted instantaneously.
comment:12 by , 16 years ago
Of course, already done - but only after too much time spent looking for the problem. Not trying to be a pain, just trying to save others the same hassle.
comment:13 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Since you've already opened another ticket (#7843) for the new bug, how about now also reopening this one (which does fix another problem)? It only requires one ticket. I'm sorry it's had an unintended side-effect and I'll look at it very shortly, but for now, just use an earlier revision for a little bit.
comment:14 by , 16 years ago
My bad - guess I assumed that that if the fix here wasn't workable, this ticket would still need attention as well. Sorry for the hassle.
comment:15 by , 16 years ago
you could have reopened this. There's just no need for two tickets (the fix here needs changing, not reverting, since it fixes a real problem, as can be seen from the patch). Anyway, we're on the same page now. It'll be fixed soon.
comment:16 by , 16 years ago
It turns out that we need to treat filename creation/display (in
particular, the upload_to path) differently depending upon whether the value is
out of the database or provided by other code and there's no reliable way to
determine that at the moment (although some later proposed changes might alter
that). So calling get_FIELD_filename on an unsaved model with a changed file
attribute will not necessarily return the same result as after the save().
comment:17 by , 16 years ago
comment:18 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Triage Stage: | Ready for checkin → Someday/Maybe |
As noted in the above commits, there are technical reasons why it's not really possible to fix this in a straightforward fashion. Tracking when an attribute is updated by code (as opposed to a database read) is something we might add in the future, in which case, this problem could be addressed at that point. For now, the simplest and practical solution is "don't do that". The model is going to be saved in any case, so save it first, then read off the filename.
Reopening and moving to Someday/Maybe.
comment:19 by , 16 years ago
Keywords: | fs-rf-fixed removed |
---|---|
milestone: | 1.0 beta |
Yeah, I'm actually not sure now why I had put fs-rf-fixed
on this one. When I add Leah's tests to the #5361 patch, it fails quite reliably, so it's clearly still an issue. I'll keep it in my head and see what happens if/when we get that potential future differentiation between db-load and otherwise. Removing all fs-rf
tags, as well as the 1.0 beta milestone, since it clearly won't get taken care of in the immediate future.
The one thing I'd note on this is that the docs probably shouldn't say "*if* you are using upload_to
," since it's actually a required argument on all FileField
s. That requirement isn't going away after #5361 either, so it's still important to make it clear.
comment:20 by , 14 years ago
Component: | Core framework → Database layer (models, ORM) |
---|---|
Patch needs improvement: | set |
3 years later, I'm not sure how relevant this is still. At the very least the patch needs to be updated to use unittests.
comment:21 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:24 by , 12 years ago
Status: | reopened → new |
---|
comment:25 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I think this is obsolete. The methods in the original patch were removed in ef48a3e69c02438db32f20531f5c679e8315d528.
Sorry for not explaining this properly already, but the
fs-rf-fixed
keyword on this ticket indicates that this fix has already been rolled into #5361.