|
21 | 21 | from ckan.plugins.toolkit import get_action, asbool, enqueue_job, ObjectNotFound, config, h
|
22 | 22 |
|
23 | 23 | 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 |
25 | 25 | from .utils import datastore_resource_exists, set_resource_metadata, modify_input_url
|
26 | 26 |
|
27 | 27 |
|
@@ -257,11 +257,12 @@ def xloader_data_into_datastore_(input, job_dict, logger):
|
257 | 257 | logger.info('File hash: %s', file_hash)
|
258 | 258 | resource['hash'] = file_hash
|
259 | 259 |
|
260 |
| - def direct_load(): |
| 260 | + def direct_load(allow_type_guessing=False): |
261 | 261 | fields = loader.load_csv(
|
262 | 262 | tmp_file.name,
|
263 | 263 | resource_id=resource['id'],
|
264 | 264 | mimetype=resource.get('format'),
|
| 265 | + allow_type_guessing=allow_type_guessing, |
265 | 266 | logger=logger)
|
266 | 267 | loader.calculate_record_count(
|
267 | 268 | resource_id=resource['id'], logger=logger)
|
@@ -317,8 +318,8 @@ def tabulator_load():
|
317 | 318 | direct_load()
|
318 | 319 | else:
|
319 | 320 | try:
|
320 |
| - direct_load() |
321 |
| - except JobError as e: |
| 321 | + direct_load(allow_type_guessing=True) |
| 322 | + except (JobError, LoaderError) as e: |
322 | 323 | logger.warning('Load using COPY failed: %s', e)
|
323 | 324 | logger.info('Trying again with tabulator')
|
324 | 325 | tabulator_load()
|
|
0 commit comments