etianen / django-s3-storage

Django Amazon S3 file storage.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error on save file

heckad opened this issue · comments

Hi all!

  File "C:\Users\Asus\Documents\Projects\python\gelio_vostok_backend\files\views.py", line 12, in upload_file
    file = FileModel.objects.create(
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\query.py", line 433, in create
    obj.save(force_insert=True, using=self.db)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\base.py", line 745, in save
    self.save_base(using=using, force_insert=force_insert,
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\base.py", line 782, in save_base
    updated = self._save_table(
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\base.py", line 887, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\base.py", line 924, in _do_insert
    return manager._insert(
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\query.py", line 1204, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\sql\compiler.py", line 1391, in execute_sql
    for sql, params in self.as_sql():
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\sql\compiler.py", line 1334, in as_sql
    value_rows = [
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\sql\compiler.py", line 1335, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\sql\compiler.py", line 1335, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\sql\compiler.py", line 1286, in pre_save_val
    return field.pre_save(obj, add=True)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\fields\files.py", line 288, in pre_save
    file.save(file.name, file.file, save=False)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\db\models\fields\files.py", line 87, in save
    self.name = self.storage.save(name, content, max_length=self.field.max_length)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\core\files\storage.py", line 51, in save
    name = self.get_available_name(name, max_length=max_length)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django_s3_storage\storage.py", line 65, in do_wrap_path_impl
    return _to_posix_path(func(self, _to_sys_path(name), *args, **kwargs))
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django_s3_storage\storage.py", line 339, in get_available_name
    return super(S3Storage, self).get_available_name(name, max_length=max_length)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django\core\files\storage.py", line 82, in get_available_name
    while self.exists(name) or (max_length and len(name) > max_length):
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django_s3_storage\storage.py", line 370, in exists
    return self.exists(name + "/")
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\django_s3_storage\storage.py", line 359, in exists
    results = self.s3_connection.list_objects_v2(
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\botocore\client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Users\Asus\.virtualenvs\gelio_vostok_backend-XP0MyTwt\lib\site-packages\botocore\client.py", line 635, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchKey: An error occurred (NoSuchKey) when calling the ListObjectsV2 operation: Unknown

Seems it's incorrect handle file not exists error!

# The AWS region to connect to.
AWS_REGION = "cdnspa.ams3"

# The full URL to the S3 endpoint.
AWS_S3_ENDPOINT_URL = "https://cdnspa.ams3.digitaloceanspaces.com"

No, what is this?

Strange, it crashes on name availability check. First time with 404 error, wich converted to OsError and trying to do self.exists(name + "/") although it should have returned False from exists method.

Please describe what should to do exists method. Should it return False if file not exists (now seems to returns None) and can I send False if I got 404 error?

Is it correct that do _wrap_errors have applied only for meta method but when we do check on directory we don't do any check on exception?

After fix works as expected!