diff --git a/SAS/TMSS/client/lib/populate.py b/SAS/TMSS/client/lib/populate.py
index 10e1541293a0b1200a4106e837e268721574dc32..005de89ce3e23c2a47f0127ec88cde634a0c5950 100644
--- a/SAS/TMSS/client/lib/populate.py
+++ b/SAS/TMSS/client/lib/populate.py
@@ -27,23 +27,23 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
     if templates_filename is None:
         templates_filename = 'templates.json'
 
-    with TMSSsession.create_from_dbcreds_for_ldap() as client:
-        templates_filepath = os.path.join(schema_dir, templates_filename)
-        logger.info("Reading templates in: %s", templates_filepath)
-        with open(templates_filepath) as templates_file:
-            templates = json.loads(templates_file.read())
+    templates_filepath = os.path.join(schema_dir, templates_filename)
+    logger.info("Reading templates in: %s", templates_filepath)
+    with open(templates_filepath) as templates_file:
+        templates = json.loads(templates_file.read())
 
-            def upload_template(template):
-                try:
-                    with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file:
-                        try:
-                            json_schema = json.loads(schema_file.read())
+        def upload_template(template):
+            try:
+                with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file:
+                    try:
+                        json_schema = json.loads(schema_file.read())
 
-                            template_path = template.pop('template')
-                            name = template.pop('name', json_schema.get('title', '<no name>'))
-                            description = template.pop('description', json_schema.get('description', '<no description>'))
-                            version = template.pop('version', '1')
+                        template_path = template.pop('template')
+                        name = template.pop('name', json_schema.get('title', '<no name>'))
+                        description = template.pop('description', json_schema.get('description', '<no description>'))
+                        version = template.pop('version', '1')
 
+                        with TMSSsession.create_from_dbcreds_for_ldap() as client:
                             if template_path == 'subtask_template' and 'type' in template:
                                 # override plain-text type by its url
                                 template['type'] = client.get_path_as_json_object('subtask_type/'+template.pop('type'))['url']
@@ -67,10 +67,10 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
                                                   description=description,
                                                   version=version,
                                                   **template)
-                        except Exception as e:
-                            logger.error(e)
-                except Exception as e:
-                    logger.error(e)
+                    except Exception as e:
+                        logger.error(e)
+            except Exception as e:
+                logger.error(e)
 
-        with futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
-            executor.map(upload_template, templates)
+    with futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
+        executor.map(upload_template, templates)