amol- / depot

Toolkit for storing files and attachments in web applications
MIT License
161 stars 41 forks source link

boto3 doens't support BufferedRandom input, workaround for when your … #58

Closed CastixGitHub closed 5 years ago

CastixGitHub commented 5 years ago

…binary file is opened in read/write/append mode

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-16.0%) to 81.895% when pulling 16041600cf99819b27203c87d1bd2361732dd3f4 on CastixGitHub:master into 7e2dcd3c72f8a2025c45a3bccc5d595b8d489876 on amol-:master.

CastixGitHub commented 5 years ago

Pasting here a complete traceback of the issue:

  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/wsgiapp.py", line 120, in __call__
    response = self.wrapped_dispatch(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/errorpage.py", line 56, in __call__
    resp = self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/transaction_manager.py", line 107, in __call__
    reraise(*exc_info)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/_compat.py", line 81, in reraise
    raise value
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/transaction_manager.py", line 83, in __call__
    response = self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/caching.py", line 54, in __call__
    return self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/session.py", line 71, in __call__
    response = self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/identity.py", line 75, in __call__
    return self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/appwrappers/i18n.py", line 71, in __call__
    return self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/app/app/config/api_wrapper.py", line 38, in __call__
    response = self.next_handler(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tgext/mailer/plugmailer.py", line 56, in __call__
    return self.dispatcher(controller, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/wsgiapp.py", line 285, in _dispatch
    return controller(environ, context)
  File "/mnt/esterno/axant/app/app/app/lib/base.py", line 32, in __call__
    return TGController.__call__(self, environ, context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/controllers/dispatcher.py", line 119, in __call__
    response = self._perform_call(context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/controllers/dispatcher.py", line 108, in _perform_call
    r = self._call(action, params, remainder=remainder, context=context)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/controllers/decoratedcontroller.py", line 119, in _call
    output = controller_caller(context_config, bound_controller_callable, remainder, params)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/decorators.py", line 44, in _decorated_controller_caller
    return application_controller_caller(tg_config, controller, remainder, params)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tgext/pluggable/i18n.py", line 22, in _add_pluggable_translations
    return next_caller(config, controller, remainder, params)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/tg/configuration/app_config.py", line 127, in call_controller
    return controller(*remainder, **params)
  File "/mnt/esterno/axant/app/app/app/controllers/admin/cinema_manager.py", line 264, in create
    supervisor_phone_number=kw.get('cinema_supervisor_phone_number'),
  File "<string>", line 4, in __init__

  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/state.py", line 441, in _initialize_instance
    manager.dispatch.init_failure(self, args, kwargs)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 154, in reraise
    raise value
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/state.py", line 438, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/ext/declarative/base.py", line 842, in _declarative_constructor
    setattr(self, k, kwargs[k])
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 268, in __set__
    instance_state(instance), instance_dict(instance), value, None
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 839, in set
    state, dict_, value, old, initiator
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 847, in fire_replace_event
    state, value, previous, initiator or self._replace_token
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/sqlalchemy/orm/events.py", line 1999, in wrap
    return fn(target, *arg)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/fields/sqlalchemy.py", line 75, in _field_set
    value = upload_type(value, column_type._upload_storage)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/fields/interfaces.py", line 52, in __init__
    self.process_content(content)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/fields/upload.py", line 37, in process_content
    file_path, file_id = self.store_content(content, filename, content_type)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/fields/upload.py", line 48, in store_content
    file_id = self.depot.create(content, filename, content_type)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/io/awss3.py", line 164, in create
    self.__save_file(key, content, filename, content_type)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/depot/io/awss3.py", line 150, in __save_file
    encrypt_key=self._encrypt_key)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/boto/s3/key.py", line 1309, in set_contents_from_file
    chunked_transfer=chunked_transfer, size=size)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/boto/s3/key.py", line 762, in send_file
    chunked_transfer=chunked_transfer, size=size)
  File "/mnt/esterno/axant/app/venv3/lib/python3.7/site-packages/boto/s3/key.py", line 932, in _send_file_internal
    self.content_type = mimetypes.guess_type(self.path)[0]
  File "/usr/lib/python3.7/mimetypes.py", line 291, in guess_type
    return _db.guess_type(url, strict)
  File "/usr/lib/python3.7/mimetypes.py", line 116, in guess_type
    scheme, url = urllib.parse.splittype(url)
  File "/usr/lib/python3.7/urllib/parse.py", line 973, in splittype
    match = _typeprog.match(url)
TypeError: expected string or bytes-like object

here boto isn't able to get the mimetype of a file because the name of the file is an integer. the issue is solved using boto3 depot.io.boto3.S3Storage.