From 5fbfa1d6e25100a67315e022e7ed3c32b01265aa Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Fri, 19 Jun 2020 19:09:36 +0300 Subject: [PATCH] Add safety guards for Model creation / cache lookup --- trains/model.py | 6 +++--- trains/storage/cache.py | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/trains/model.py b/trains/model.py index 8c49abbe..9e7c4e82 100644 --- a/trains/model.py +++ b/trains/model.py @@ -566,7 +566,7 @@ class InputModel(Model): if task: comment = 'Imported by task id: {}'.format(task.id) + ('\n' + comment if comment else '') project_id = task.project - name = name or task.name + name = name or 'Imported by {}'.format(task.name or '') # do not register the Task, because we do not want it listed after as "output model", # the Task never actually created the Model task_id = None @@ -931,7 +931,7 @@ class OutputModel(BaseModel): self._floating_data = create_dummy_model( design=_Model._wrap_design(config_text), labels=label_enumeration or task.get_labels_enumeration(), - name=name or task.name, + name=name or self._task.name, tags=tags, comment='{} by task id: {}'.format('Created' if not base_model_id else 'Overwritten', task.id) + ('\n' + comment if comment else ''), @@ -946,7 +946,7 @@ class OutputModel(BaseModel): design=self._floating_data.design, task_id=self._task.id, project_id=self._task.project, - name=self._floating_data.name or task.name, + name=self._floating_data.name or self._task.name, comment=('{}\n{}'.format(_base_model.comment, self._floating_data.comment) if (_base_model.comment and self._floating_data.comment and self._floating_data.comment not in _base_model.comment) diff --git a/trains/storage/cache.py b/trains/storage/cache.py index 120a9ddd..40e9b484 100644 --- a/trains/storage/cache.py +++ b/trains/storage/cache.py @@ -136,7 +136,13 @@ class CacheManager(object): def get_remote_url(local_copy_path): if not CacheManager._local_to_remote_url_lookup: return local_copy_path - conform_local_copy_path = StorageHelper.conform_url(local_copy_path) + + # noinspection PyBroadException + try: + conform_local_copy_path = StorageHelper.conform_url(str(local_copy_path)) + except Exception: + return local_copy_path + return CacheManager._local_to_remote_url_lookup.get(hash(conform_local_copy_path), local_copy_path) @staticmethod @@ -144,10 +150,23 @@ class CacheManager(object): # so that we can disable the cache lookup altogether if CacheManager._local_to_remote_url_lookup is None: return - remote_url = StorageHelper.conform_url(remote_url) + + # noinspection PyBroadException + try: + remote_url = StorageHelper.conform_url(str(remote_url)) + except Exception: + return + if remote_url.startswith('file://'): return - local_copy_path = StorageHelper.conform_url(local_copy_path) + + local_copy_path = str(local_copy_path) + + # noinspection PyBroadException + try: + local_copy_path = StorageHelper.conform_url(local_copy_path) + except Exception: + pass CacheManager._local_to_remote_url_lookup[hash(local_copy_path)] = remote_url # protect against overuse, so we do not blowup the memory if len(CacheManager._local_to_remote_url_lookup) > CacheManager.__local_to_remote_url_lookup_max_size: