1212from typing import List # the legacy Workspaces class below unfortunately defines its own method called list
1313
1414
15- def _make_body (mapping , source_key = 'source' ):
15+ def _make_body (mapping , source_key = 'source' , preserve : bool = True ):
1616 """
1717 Given a dict mapping Keboola tables to aliases, construct the body of
1818 the HTTP request to load said tables.
@@ -22,7 +22,7 @@ def _make_body(mapping, source_key='source'):
2222 be loaded (ie. 'in.c-bucker.table_name') and values contain the
2323 aliases to which they will be loaded (ie. 'table_name').
2424 """
25- body = {}
25+ body = {'preserve' : str ( preserve ). lower () }
2626 template = 'input[{0}][{1}]'
2727 for i , (k , v ) in enumerate (mapping .items ()):
2828 body [template .format (i , source_key )] = k
@@ -91,7 +91,7 @@ def create(self, backend=None, timeout=None, login_type=None, public_key=None, r
9191 'statementTimeoutSeconds' : timeout ,
9292 'loginType' : login_type ,
9393 'publicKey' : public_key ,
94- 'readOnlyStorageAccess' : str (read_all_objects ).lower ()
94+ 'readOnlyStorageAccess' : str (read_all_objects ).lower () # convert bool to lowercase true or false
9595 }
9696
9797 return self ._post (self .base_url , data = body )
@@ -159,16 +159,14 @@ def load_tables(self, workspace_id: int | str, table_mapping: dict | List[dict],
159159 if load_type not in ['load' , 'load-clone' ]:
160160 raise ValueError ("Invalid load_type: {}, supports only load and load-clone" .format (load_type ))
161161
162- url = '{}/{}/{}' . format ( self .base_url , workspace_id , load_type )
162+ url = "/" . join ([ self .base_url , workspace_id , load_type ] )
163163
164164 req = None
165165 if isinstance (table_mapping , dict ):
166- body = _make_body (table_mapping )
167- body ['preserve' ] = str (preserve ).lower ()
166+ body = _make_body (table_mapping , preserve = preserve )
168167 req = self ._post (url , data = body )
169168 elif isinstance (table_mapping , list ):
170- body = {'input' : table_mapping }
171- body ['preserve' ] = str (preserve ).lower ()
169+ body = {'input' : table_mapping , 'preserve' : str (preserve ).lower ()}
172170 req = self ._post (url , json = body )
173171
174172 return req
0 commit comments