Skip to content

Commit 08285bc

Browse files
committed
refine Tabulator fallback behaviour
- If field counts or names have changed, then fall back to Tabulator and start from scratch, but if only the types have changed, then try to preserve the Data Dictionary and proceed with COPY.
1 parent cde3066 commit 08285bc

File tree

4 files changed

+262
-224
lines changed

4 files changed

+262
-224
lines changed

ckanext/xloader/jobs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ckan.plugins.toolkit import get_action, asbool, enqueue_job, ObjectNotFound, config, h
2222

2323
from . import db, loader
24-
from .job_exceptions import JobError, HTTPError, DataTooBigError, FileCouldNotBeLoadedError, XLoaderTimeoutError
24+
from .job_exceptions import JobError, HTTPError, DataTooBigError, FileCouldNotBeLoadedError, LoaderError, XLoaderTimeoutError
2525
from .utils import datastore_resource_exists, set_resource_metadata, modify_input_url
2626

2727

@@ -257,11 +257,12 @@ def xloader_data_into_datastore_(input, job_dict, logger):
257257
logger.info('File hash: %s', file_hash)
258258
resource['hash'] = file_hash
259259

260-
def direct_load():
260+
def direct_load(allow_type_guessing=False):
261261
fields = loader.load_csv(
262262
tmp_file.name,
263263
resource_id=resource['id'],
264264
mimetype=resource.get('format'),
265+
allow_type_guessing=allow_type_guessing,
265266
logger=logger)
266267
loader.calculate_record_count(
267268
resource_id=resource['id'], logger=logger)
@@ -317,8 +318,8 @@ def tabulator_load():
317318
direct_load()
318319
else:
319320
try:
320-
direct_load()
321-
except JobError as e:
321+
direct_load(allow_type_guessing=True)
322+
except (JobError, LoaderError) as e:
322323
logger.warning('Load using COPY failed: %s', e)
323324
logger.info('Trying again with tabulator')
324325
tabulator_load()

0 commit comments

Comments
 (0)