question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add documents with the same filename created issue after deletion of one

See original GitHub issue

Issue Summary

We have a content editor who accidentally added the same document twice to the Document Library, and then deleted one. After deleting the one, the file was removed. This led to the following error when the remaining document was attempted to be edited:

An error occurred (404) when calling the HeadObject operation: Not Found

Steps to Reproduce

  1. Visit ‘/[admin]/documents/multiple/add/’
  2. Upload a document and change the title to Doc 1
  3. Upload the same document and change the title to Doc 2
  4. Delete Doc 2
  5. Edit Doc 1

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

Several options:

  1. When deleting, make sure the file name is not associated with any other Document; if it is, delete the row in the database, and not the file itself.
  2. Ensure that file names of uploads are unique.

Technical details

  • Python version: 3.5.2
  • Django version: 1.10.2
  • Wagtail version: 1.6.3
  • Browser version: Chrome 53

We are using django-storages and boto3 to store our assets on Amazon S3.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
FlipperPAcommented, Dec 2, 2016

Just to follow up, I’d recommend only doing this for your media files, not static file. Here’s an example custom_storages.py I use:

from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage


class StaticStorage(S3Boto3Storage):
    location = settings.STATICFILES_LOCATION


class MediaStorage(S3Boto3Storage):
    location = settings.MEDIAFILES_LOCATION
    file_overwrite = False
0reactions
benpettycommented, Oct 30, 2017

Hi @gasman - thanks for the quick response. I’m running wagtail==1.13, django==1.11.6, boto3==1.4.7, botocore==1.7.30.

From the cms /images/ chooser, JS console prints a pair of 403s for each item with duplicate file names (ending in .max-165x165.png). Yet the thumbnails are visible. Following link to edit page returns 500:

botocore.exceptions:ClientError
/wagtail.wagtailimages.views.images:edit

Stack trace
botocore.exceptions:ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
Traceback (most recent call last):
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/api/web_transaction.py", line 1198, in _nr_wsgi_application_wrapper_
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in get_response
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 527, in wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/views/decorators/cache.py", line 43, in _cache_controlled
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailadmin/urls/__init__.py", line 96, in wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailadmin/decorators.py", line 31, in decorated_view
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailadmin/utils.py", line 140, in wrapped_view_func
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/views/images.py", line 147, in edit
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/models.py", line 105, in get_file_size
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/db/models/fields/files.py", line 77, in size
File "/var/www/tomorrow/env/lib/python3.5/site-packages/storages/backends/s3boto3.py", line 511, in size
File "/var/www/tomorrow/env/lib/python3.5/site-packages/boto3/resources/factory.py", line 339, in property_loader
File "/var/www/tomorrow/env/lib/python3.5/site-packages/boto3/resources/factory.py", line 505, in do_action
File "/var/www/tomorrow/env/lib/python3.5/site-packages/boto3/resources/action.py", line 83, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/botocore/client.py", line 312, in _api_call
File "/var/www/tomorrow/env/lib/python3.5/site-packages/botocore/client.py", line 605, in _make_api_call

When trying to add a broken image to a page, JS console prints 403 not founds from cloudfrount, and 500s from /cms/images/chooser/129/select_format/.

wagtail.wagtailimages.models:SourceImageIOError
/wagtail.wagtailimages.views.chooser:chooser_select_format

Stack trace
wagtail.wagtailimages.models:SourceImageIOError: File does not exist: media/original_images/foo.png
Traceback (most recent call last):
File "/var/www/tomorrow/env/lib/python3.5/site-packages/gunicorn/workers/sync.py", line 30, in accept
File "/var/www/tomorrow/env/lib/python3.5/site-packages/gunicorn/workers/sync.py", line 135, in handle
File "/var/www/tomorrow/env/lib/python3.5/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/api/web_transaction.py", line 1309, in _nr_wsgi_application_wrapper_
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/api/web_transaction.py", line 837, in __init__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/api/web_transaction.py", line 1198, in _nr_wsgi_application_wrapper_
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in get_response
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 1182, in _wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
File "/var/www/tomorrow/env/lib/python3.5/site-packages/newrelic/hooks/framework_django.py", line 527, in wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/django/views/decorators/cache.py", line 43, in _cache_controlled
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailadmin/urls/__init__.py", line 96, in wrapper
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailadmin/decorators.py", line 31, in decorated_view
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/views/chooser.py", line 169, in chooser_select_format
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/models.py", line 271, in get_rendition
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/models.py", line 367, in run
File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
File "/var/www/tomorrow/env/lib/python3.5/site-packages/wagtail/wagtailimages/models.py", line 173, in get_willow_image
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to reattach a file with the name that's same as a ...
Solution/Workaround · After you delete the attachment for the list item, click Save. Edit the list item again, reattach the file, and then...
Read more >
Can't create file with deleted file name at android 10
I found a solution myself: int fileNo = 0; Uri uri = saveToUri(fileName, contentType, seconds, relativePath); if (uri == null) { while ...
Read more >
Same file name in one folder - Dropbox Community
I've moved a folder into a folder with another folder with the exact same name... I didn't realise DB would delete the old...
Read more >
Why is space not being freed from disk after deleting a file in ...
The first one listed ([A] instance of the file), has been deleted from the directory hierarchy of the filesystem but because it is...
Read more >
Delete and restore files in Google Drive - Android
Files in trash will be automatically deleted after 30 days. You can restore files from ... To remove a file from your Drive,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found