Opened 16 years ago

Closed 15 years ago

Last modified 13 years ago

#10258 closed (fixed)

many files with the same file name cannot be saved correctly

Reported by: liangent Owned by: duncan
Component: File uploads/storage Version: 1.0
Severity: Keywords:
Cc: ianschenck Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The current Django code add '_' to file name in order to avoid overwrite saved files.
However, if I save many files with the same file name, Django will add many '_'s.
If the file name is too long, file will be saved correctly, but path in database will be truncated.

/var/lib/python-support/python2.5/django/db/backends/mysql/base.py:83: Warning: Data truncated for column 'output' at row 1
  return self.cursor.execute(query, args)

Then when I try to get that file according to the path saved in database, it will fail...

Attachments (3)

10258.diff (3.3 KB ) - added by ianschenck 16 years ago.
patch
10258.2.diff (3.9 KB ) - added by Thilo 16 years ago.
Added one more doctest which uploads 10 files and checks for their names.
10258-on-9160.diff (4.7 KB ) - added by Thilo 16 years ago.
Patch that applies when patch from #9610 has been applied before. Apart from that its identical to 10258.2.diff

Download all attachments as: .zip

Change History (16)

comment:1 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:2 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 by Marcelo Ramos, 16 years ago

Is adding the creation timestamp to the filename a good solution for this?

comment:4 by Marcelo Ramos, 16 years ago

I mean, that way multiple files with the same filename can be saved with different names keeping them short.

comment:5 by Bob Thomas, 16 years ago

Timestamps could still be long. Appending a number to the end of a filename would be much better than more underscores, though.

Something like:

name
name_0
name_1
name_2
...etc

by ianschenck, 16 years ago

Attachment: 10258.diff added

patch

comment:6 by ianschenck, 16 years ago

Cc: ianschenck added
Has patch: set

comment:7 by duncan, 16 years ago

Owner: changed from nobody to duncan

comment:8 by duncan, 16 years ago

Needs tests: set

Patch to the code looks fairly sensible to me. I think we could do with some more tests though.

comment:9 by Andy Durdin, 16 years ago

Fixing this may affect the patch or tests for #9610

by Thilo, 16 years ago

Attachment: 10258.2.diff added

Added one more doctest which uploads 10 files and checks for their names.

comment:10 by Thilo, 16 years ago

#9610 indeed conflicts with this issue: both of the patches change the same lines in django/core/files/storage.py. I merged them locally and created a diff for 10258 which will apply on top of #9610. Attachment follows.

by Thilo, 16 years ago

Attachment: 10258-on-9160.diff added

Patch that applies when patch from #9610 has been applied before. Apart from that its identical to 10258.2.diff

comment:11 by Jacob, 15 years ago

milestone: 1.11.2

Punting to 1.2. For now, use a custom upload_to and/or override the storage engine's get_available_filename function.

comment:12 by Jacob, 15 years ago

Resolution: fixed
Status: newclosed

(In [12552]) Fixed #10258: handle duplicate file names better.

Instead of just continually appending "_" to duplicate file names, Django's
default storage now appends _1, _2, _3, etc.

Thanks to ianschenck and Thilo.

comment:13 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top