Django

Code

Ticket #7843 (closed: fixed)

Opened 5 months ago

Last modified 4 months ago

r7986 breaks uploaded files stored in date-based directories

Reported by: carljm Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation:
Needs tests: Patch needs improvement:

Description

After updating to a Django revision post- [7986], get_FIELD_url is broken for all FileField? and ImageField? uploads using an upload_to with date-based directory parts.

[7986] updates get_FIELD_url to call field.get_filename on the DB-stored path. field.get_filename only uses the basename of its argument, and calls field.get_directory_name for the directory part. field.get_directory_name uses datetime.now() for interpolating the date parts into upload_to.

From django/db/models/fields/init.py:

    def get_directory_name(self):
        return os.path.normpath(force_unicode(datetime.datetime.now().strftime(

    def get_filename(self, filename):
        from django.utils.text import get_valid_filename
        f = os.path.join(self.get_directory_name(), get_valid_filename(os.path.
        return os.path.normpath(f)

This means that instead of returning a URL with the correct path that is stored in the DB, get_FIELD_url now returns a URL that always has the current date interpolated into it. For any file uploaded before today, that will be a broken link.

This is a showstopper bug; please revert [7986] as quickly as possible.

Attachments

Change History

07/19/08 17:26:33 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7998]) Reverted [7986].

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().

Refs #5619. Fixed #7843.


Add/Change #7843 (r7986 breaks uploaded files stored in date-based directories)




Change Properties
Action