# Buggy code
def _retrieve_tar(self, target_filename: Text) -> None:
    """Downloads a model that has previously been persisted to s3."""

    with open(target_filename, "wb") as f:
        self.bucket.download_fileobj(target_filename, f)


# Traceback (FileNotFoundError)
2019-12-06 09:04:53 ERROR    rasa.core.agent  - Could not load model due to [Errno 2] No such file or directory: 'projectA/20191205-192442.tar.gz'.
Experienced exception while trying to serve
Traceback (most recent call last):
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/app.py", line 1096, in run
serve(**server_settings)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/server.py", line 742, in serve
trigger_events(before_start, loop)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/server.py", line 604, in trigger_events
loop.run_until_complete(result)
File "uvloop/loop.pyx", line 1417, in uvloop.loop.Loop.run_until_complete
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/run.py", line 244, in load_agent_on_start
action_endpoint=endpoints.action,
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/agent.py", line 249, in load_agent
model_server=model_server,
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/agent.py", line 932, in load_from_remote_storage
persistor.retrieve(model_name, target_path)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/nlu/persistor.py", line 55, in retrieve
self._retrieve_tar(tar_name)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/nlu/persistor.py", line 157, in _retrieve_tar
with io.open(target_filename, "wb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'projectA/20191205-192442.tar.gz'
Traceback (most recent call last):
File "/Users/cianclarke/Library/Python/3.7/bin/rasa", line 8, in <module>
sys.exit(main())
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/__main__.py", line 76, in main
cmdline_arguments.func(cmdline_arguments)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/cli/run.py", line 100, in run
rasa.run(**vars(args))
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/run.py", line 56, in run
**kwargs
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/run.py", line 202, in serve_application
backlog=int(os.environ.get("SANIC_BACKLOG", "100")),
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/app.py", line 1096, in run
serve(**server_settings)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/server.py", line 742, in serve
trigger_events(before_start, loop)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/sanic/server.py", line 604, in trigger_events
loop.run_until_complete(result)
File "uvloop/loop.pyx", line 1417, in uvloop.loop.Loop.run_until_complete
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/run.py", line 244, in load_agent_on_start
action_endpoint=endpoints.action,
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/agent.py", line 249, in load_agent
model_server=model_server,
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/core/agent.py", line 932, in load_from_remote_storage
persistor.retrieve(model_name, target_path)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/nlu/persistor.py", line 55, in retrieve
self._retrieve_tar(tar_name)
File "/Users/cianclarke/Library/Python/3.7/lib/python/site-packages/rasa/nlu/persistor.py", line 157, in _retrieve_tar
with io.open(target_filename, "wb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'projectA/20191205-192442.tar.gz'

# Fixed code
def _retrieve_tar(self, model_path: Text) -> None:
    """Downloads a model that has previously been persisted to s3."""
    tar_name = os.path.basename(model_path)
    with open(tar_name, "wb") as f:
        self.bucket.download_fileobj(model_path, f)