ckanext-xloader 2.5.2__tar.gz → 2.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ckanext_xloader-2.5.2/ckanext_xloader.egg-info → ckanext_xloader-2.7.0}/PKG-INFO +44 -5
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/README.md +20 -4
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/config_declaration.yaml +10 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/jobs.py +5 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/loader.py +22 -5
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_jobs.py +43 -7
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_loader.py +96 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/utils.py +1 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0/ckanext_xloader.egg-info}/PKG-INFO +44 -5
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext_xloader.egg-info/SOURCES.txt +0 -2
- ckanext_xloader-2.7.0/ckanext_xloader.egg-info/requires.txt +23 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/pyproject.toml +32 -4
- ckanext_xloader-2.5.2/ckanext_xloader.egg-info/requires.txt +0 -4
- ckanext_xloader-2.5.2/dev-requirements.txt +0 -8
- ckanext_xloader-2.5.2/requirements.txt +0 -11
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/CHANGELOG +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/LICENSE +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/MANIFEST.in +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/__init__.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/__init__.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/action.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/auth.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/cli.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/command.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/db.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/helpers.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/interfaces.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/job_exceptions.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/parser.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/plugin.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/schema.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/datastore/snippets/dictionary_form.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/resource_edit_base.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/resource_read.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/snippets/resource_info.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/snippets/resource_item.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/snippets/resources.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/xloader/confirm_datastore_delete.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/xloader/resource_data.html +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/__init__.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/ckan_setup.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/fixtures.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_action.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_chunks.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_db.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_parser.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_plugin.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/tests/test_utils.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/views.py +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/webassets/css/xloader.css +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/webassets/webassets.yml +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext_xloader.egg-info/dependency_links.txt +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext_xloader.egg-info/entry_points.txt +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext_xloader.egg-info/top_level.txt +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/setup.cfg +0 -0
- {ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ckanext-xloader
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.7.0
|
|
4
4
|
Summary: Express Loader - quickly load data into CKAN DataStore
|
|
5
5
|
Author: David Read (davidread), Patricio Del Boca (pdelboca)
|
|
6
6
|
Author-email: ThrawnCA <carl.antuar@smartservice.qld.gov.au>, "Jesse Vickery (JVickery-TBS)" <jesse.vickery@tbs-sct.gc.ca>, "Adrià Mercader (amercader)" <amercadero@gmail.com>, "Brett Jones (kowh-ai)" <datashades@linkdigital.com.au>, "William Dutton (duttonw)" <william.dutton@qld.gov.au>
|
|
@@ -12,12 +12,35 @@ Keywords: CKAN,extension,datastore
|
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
18
|
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.10
|
|
16
20
|
Description-Content-Type: text/markdown
|
|
17
21
|
License-File: LICENSE
|
|
18
22
|
Requires-Dist: typing_extensions
|
|
23
|
+
Requires-Dist: ckantoolkit>=0.0.7
|
|
24
|
+
Requires-Dist: requests>=2.34.2
|
|
25
|
+
Requires-Dist: six>=1.17.0
|
|
26
|
+
Requires-Dist: tabulator==1.53.5
|
|
27
|
+
Requires-Dist: Unidecode==1.4.0
|
|
28
|
+
Requires-Dist: python-dateutil>=2.9.0.post0
|
|
29
|
+
Requires-Dist: certifi>=2026.7.22
|
|
30
|
+
Requires-Dist: chardet==7.6.0
|
|
31
|
+
Requires-Dist: idna>=3.20
|
|
32
|
+
Requires-Dist: urllib3>=2.8.0
|
|
33
|
+
Requires-Dist: zipp>=4.1.0
|
|
19
34
|
Provides-Extra: test
|
|
20
35
|
Requires-Dist: pytest-factoryboy; extra == "test"
|
|
36
|
+
Requires-Dist: responses==0.10.9; extra == "test"
|
|
37
|
+
Requires-Dist: mock==5.2.0; extra == "test"
|
|
38
|
+
Requires-Dist: flake8; extra == "test"
|
|
39
|
+
Requires-Dist: pytest-ckan; extra == "test"
|
|
40
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
41
|
+
Requires-Dist: requests>=2.34.2; extra == "test"
|
|
42
|
+
Requires-Dist: urllib3>=2.8.0; extra == "test"
|
|
43
|
+
Requires-Dist: zipp>=4.1.0; extra == "test"
|
|
21
44
|
Dynamic: license-file
|
|
22
45
|
|
|
23
46
|
# XLoader - ckanext-xloader
|
|
@@ -136,10 +159,10 @@ Compatibility with core CKAN versions:
|
|
|
136
159
|
|
|
137
160
|
| CKAN version | Compatibility |
|
|
138
161
|
|--------------|-------------------------------------------------------|
|
|
139
|
-
| 2.7 | no
|
|
140
|
-
| 2.8 | no
|
|
141
|
-
| 2.9 | no
|
|
142
|
-
| 2.10 | yes
|
|
162
|
+
| 2.7 | no (last supported version: 0.12.2) |
|
|
163
|
+
| 2.8 | no (last supported version: 0.12.2) |
|
|
164
|
+
| 2.9 | no (last supported version: 1.2.x) |
|
|
165
|
+
| 2.10 | yes 3.10+ (python 3.9 last support version: 2.5.1 ) |
|
|
143
166
|
| 2.11 | yes |
|
|
144
167
|
| 2.12 | yes |
|
|
145
168
|
|
|
@@ -396,6 +419,22 @@ If set to 0 (default) files that exceed the `max_content_length` will
|
|
|
396
419
|
not be loaded into the datastore.
|
|
397
420
|
|
|
398
421
|
|
|
422
|
+
#### ckanext.xloader.type_guessing_sample_size
|
|
423
|
+
|
|
424
|
+
Example:
|
|
425
|
+
|
|
426
|
+
```
|
|
427
|
+
ckanext.xloader.type_guessing_sample_size = 1000
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Default value: `100`
|
|
431
|
+
|
|
432
|
+
The number of rows xloader samples from the start of a file to guess
|
|
433
|
+
the header row and the column types. Increase this if values that
|
|
434
|
+
would change a column's type (e.g. decimal numbers) only appear
|
|
435
|
+
further down the file. Larger values use more memory and time.
|
|
436
|
+
|
|
437
|
+
|
|
399
438
|
#### ckanext.xloader.ssl_verify
|
|
400
439
|
|
|
401
440
|
Example:
|
|
@@ -114,10 +114,10 @@ Compatibility with core CKAN versions:
|
|
|
114
114
|
|
|
115
115
|
| CKAN version | Compatibility |
|
|
116
116
|
|--------------|-------------------------------------------------------|
|
|
117
|
-
| 2.7 | no
|
|
118
|
-
| 2.8 | no
|
|
119
|
-
| 2.9 | no
|
|
120
|
-
| 2.10 | yes
|
|
117
|
+
| 2.7 | no (last supported version: 0.12.2) |
|
|
118
|
+
| 2.8 | no (last supported version: 0.12.2) |
|
|
119
|
+
| 2.9 | no (last supported version: 1.2.x) |
|
|
120
|
+
| 2.10 | yes 3.10+ (python 3.9 last support version: 2.5.1 ) |
|
|
121
121
|
| 2.11 | yes |
|
|
122
122
|
| 2.12 | yes |
|
|
123
123
|
|
|
@@ -374,6 +374,22 @@ If set to 0 (default) files that exceed the `max_content_length` will
|
|
|
374
374
|
not be loaded into the datastore.
|
|
375
375
|
|
|
376
376
|
|
|
377
|
+
#### ckanext.xloader.type_guessing_sample_size
|
|
378
|
+
|
|
379
|
+
Example:
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
ckanext.xloader.type_guessing_sample_size = 1000
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Default value: `100`
|
|
386
|
+
|
|
387
|
+
The number of rows xloader samples from the start of a file to guess
|
|
388
|
+
the header row and the column types. Increase this if values that
|
|
389
|
+
would change a column's type (e.g. decimal numbers) only appear
|
|
390
|
+
further down the file. Larger values use more memory and time.
|
|
391
|
+
|
|
392
|
+
|
|
377
393
|
#### ckanext.xloader.ssl_verify
|
|
378
394
|
|
|
379
395
|
Example:
|
|
@@ -147,6 +147,16 @@ groups:
|
|
|
147
147
|
not be loaded into the datastore.
|
|
148
148
|
type: int
|
|
149
149
|
required: false
|
|
150
|
+
- key: ckanext.xloader.type_guessing_sample_size
|
|
151
|
+
default: 100
|
|
152
|
+
example: 1000
|
|
153
|
+
description: |
|
|
154
|
+
The number of rows xloader samples from the start of a file to guess
|
|
155
|
+
the header row and the column types. Increase this if values that
|
|
156
|
+
would change a column's type (e.g. decimal numbers) only appear
|
|
157
|
+
further down the file. Larger values use more memory and time.
|
|
158
|
+
type: int
|
|
159
|
+
required: false
|
|
150
160
|
- key: ckanext.xloader.ssl_verify
|
|
151
161
|
default: True
|
|
152
162
|
example: True
|
|
@@ -162,6 +162,11 @@ def xloader_data_into_datastore(input):
|
|
|
162
162
|
logger.error('xloader error: job_id %s already exists', job_id)
|
|
163
163
|
errored = True
|
|
164
164
|
except Exception as e:
|
|
165
|
+
if isinstance(e, JobTimeoutException):
|
|
166
|
+
# The RQ timeout can fire anywhere (not just in the download or
|
|
167
|
+
# load blocks that translate it), so report it consistently here.
|
|
168
|
+
logger.warning('Job timed out after %ss', retried_job_timeout)
|
|
169
|
+
e = JobError('Job timed out after {}s'.format(retried_job_timeout))
|
|
165
170
|
error_state = {'errored': errored}
|
|
166
171
|
retry = handle_retryable_error(e, input, job_id, job_dict, logger, error_state)
|
|
167
172
|
if retry:
|
|
@@ -10,7 +10,7 @@ import tempfile
|
|
|
10
10
|
from decimal import Decimal
|
|
11
11
|
|
|
12
12
|
import psycopg2
|
|
13
|
-
from chardet
|
|
13
|
+
from chardet import UniversalDetector
|
|
14
14
|
from six.moves import zip
|
|
15
15
|
from tabulator import config as tabulator_config, EncodingError, Stream, TabulatorException
|
|
16
16
|
from unidecode import unidecode
|
|
@@ -23,6 +23,10 @@ from .job_exceptions import FileCouldNotBeLoadedError, LoaderError
|
|
|
23
23
|
from .parser import CSV_SAMPLE_LINES, TypeConverter
|
|
24
24
|
from .utils import cleanup_temp_file, datastore_resource_exists, headers_guess, type_guess
|
|
25
25
|
|
|
26
|
+
from ckan.plugins.toolkit import config, _
|
|
27
|
+
|
|
28
|
+
import ckanext.datastore.backend.postgres as datastore_db
|
|
29
|
+
|
|
26
30
|
|
|
27
31
|
def _notify_datastore_before_update(resource_id, existing_fields, new_headers):
|
|
28
32
|
"""Notify IXloader plugins that the DataStore table for ``resource_id``
|
|
@@ -40,9 +44,6 @@ def _notify_datastore_before_update(resource_id, existing_fields, new_headers):
|
|
|
40
44
|
new_headers=new_headers,
|
|
41
45
|
)
|
|
42
46
|
|
|
43
|
-
from ckan.plugins.toolkit import config, _
|
|
44
|
-
|
|
45
|
-
import ckanext.datastore.backend.postgres as datastore_db
|
|
46
47
|
|
|
47
48
|
get_write_engine = datastore_db.get_write_engine
|
|
48
49
|
create_indexes = datastore_db.create_indexes
|
|
@@ -53,6 +54,21 @@ tabulator_config.CSV_SAMPLE_LINES = CSV_SAMPLE_LINES
|
|
|
53
54
|
|
|
54
55
|
SINGLE_BYTE_ENCODING = 'cp1252'
|
|
55
56
|
|
|
57
|
+
# Number of rows tabulator reads as the sample used for header and type guessing.
|
|
58
|
+
DEFAULT_TYPE_GUESSING_SAMPLE_SIZE = 100
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_type_guessing_sample_size():
|
|
62
|
+
"""Return the number of rows to sample for header and type guessing,
|
|
63
|
+
from ``ckanext.xloader.type_guessing_sample_size``. Invalid or
|
|
64
|
+
non-positive values fall back to the default."""
|
|
65
|
+
try:
|
|
66
|
+
size = int(config.get('ckanext.xloader.type_guessing_sample_size',
|
|
67
|
+
DEFAULT_TYPE_GUESSING_SAMPLE_SIZE))
|
|
68
|
+
except (TypeError, ValueError):
|
|
69
|
+
return DEFAULT_TYPE_GUESSING_SAMPLE_SIZE
|
|
70
|
+
return size if size > 0 else DEFAULT_TYPE_GUESSING_SAMPLE_SIZE
|
|
71
|
+
|
|
56
72
|
|
|
57
73
|
def _should_keep_cell(index, cell, header_count, row_number=None):
|
|
58
74
|
"""Return whether a cell should be kept, given it may exceed the headers.
|
|
@@ -128,6 +144,7 @@ class UnknownEncodingStream(object):
|
|
|
128
144
|
self.filepath = filepath
|
|
129
145
|
self.file_format = file_format
|
|
130
146
|
self.stream_args = kwargs
|
|
147
|
+
self.stream_args.setdefault('sample_size', get_type_guessing_sample_size())
|
|
131
148
|
self.decoding_result = decoding_result # {'encoding': 'EUC-JP', 'confidence': 0.99}
|
|
132
149
|
|
|
133
150
|
def __enter__(self):
|
|
@@ -984,7 +1001,7 @@ def calculate_record_count(resource_id, logger):
|
|
|
984
1001
|
engine = get_write_engine()
|
|
985
1002
|
with engine.connect() as conn:
|
|
986
1003
|
conn.execute(sa.text("ANALYZE \"{resource_id}\";"
|
|
987
|
-
|
|
1004
|
+
.format(resource_id=resource_id)))
|
|
988
1005
|
|
|
989
1006
|
|
|
990
1007
|
def identifier(s, escape_binds=False):
|
|
@@ -5,6 +5,7 @@ from typing import Any
|
|
|
5
5
|
import pytest
|
|
6
6
|
import io
|
|
7
7
|
import os
|
|
8
|
+
import time
|
|
8
9
|
|
|
9
10
|
from datetime import datetime
|
|
10
11
|
|
|
@@ -40,12 +41,19 @@ def get_large_response(download_url, headers):
|
|
|
40
41
|
return resp
|
|
41
42
|
|
|
42
43
|
|
|
43
|
-
def
|
|
44
|
-
"""Mock jobs.get_response()
|
|
44
|
+
def get_slow_data_response(download_url, headers):
|
|
45
|
+
"""Mock jobs.get_response() so the download outlasts the RQ job timeout,
|
|
46
|
+
regardless of how fast the machine is."""
|
|
45
47
|
resp = Response()
|
|
46
|
-
|
|
47
|
-
resp.raw = io.BytesIO(f_content.encode())
|
|
48
|
+
resp.raw = io.BytesIO(_TEST_FILE_CONTENT.encode())
|
|
48
49
|
resp.headers = headers
|
|
50
|
+
|
|
51
|
+
def slow_iter_content(chunk_size=1, decode_unicode=False):
|
|
52
|
+
yield _TEST_FILE_CONTENT.encode()
|
|
53
|
+
time.sleep(10) # well beyond the 2s job timeout
|
|
54
|
+
yield _TEST_LARGE_FILE_CONTENT.encode()
|
|
55
|
+
|
|
56
|
+
resp.iter_content = slow_iter_content
|
|
49
57
|
return resp
|
|
50
58
|
|
|
51
59
|
|
|
@@ -212,16 +220,44 @@ class TestXLoaderJobs(helpers.FunctionalRQTestBase):
|
|
|
212
220
|
resource = helpers.call_action("resource_show", id=data["metadata"]["resource_id"])
|
|
213
221
|
assert resource["datastore_contains_all_records_of_source_file"] is False
|
|
214
222
|
|
|
215
|
-
def
|
|
223
|
+
def _assert_job_times_out(self, cli, data, target, replacement, check_tmp_files=True):
|
|
224
|
+
"""Run a job with a 2s RQ timeout while `target` is replaced by
|
|
225
|
+
something that outlasts it, and check the timeout is reported."""
|
|
216
226
|
file_suffix = 'multiplication_2.csv'
|
|
217
227
|
self.enqueue(jobs.xloader_data_into_datastore, [data], rq_kwargs=dict(timeout=2))
|
|
218
|
-
with mock.patch(
|
|
228
|
+
with mock.patch(target, replacement):
|
|
219
229
|
stdout = cli.invoke(ckan, ["jobs", "worker", "--burst"]).output
|
|
220
|
-
|
|
230
|
+
assert "Job timed out after" in stdout
|
|
231
|
+
assert "Express Load completed" not in stdout
|
|
232
|
+
if check_tmp_files:
|
|
221
233
|
for f in _get_temp_files():
|
|
222
234
|
# make sure that the tmp file has been closed/deleted in job timeout exception handling
|
|
223
235
|
assert file_suffix not in f
|
|
224
236
|
|
|
237
|
+
def test_data_with_rq_job_timeout(self, cli, data):
|
|
238
|
+
"""Timeout while downloading the data."""
|
|
239
|
+
self._assert_job_times_out(
|
|
240
|
+
cli, data, "ckanext.xloader.jobs.get_response", get_slow_data_response)
|
|
241
|
+
|
|
242
|
+
def test_data_with_rq_job_timeout_during_load(self, cli, data):
|
|
243
|
+
"""Timeout while loading the (already downloaded) data."""
|
|
244
|
+
def slow_load_csv(*args, **kwargs):
|
|
245
|
+
time.sleep(10) # well beyond the 2s job timeout
|
|
246
|
+
|
|
247
|
+
with mock.patch("ckanext.xloader.jobs.get_response", get_response):
|
|
248
|
+
self._assert_job_times_out(
|
|
249
|
+
cli, data, "ckanext.xloader.loader.load_csv", slow_load_csv)
|
|
250
|
+
|
|
251
|
+
def test_data_with_rq_job_timeout_outside_download_and_load(self, cli, data):
|
|
252
|
+
"""Timeout outside the download/load blocks is still reported as a
|
|
253
|
+
job timeout, not as a generic error."""
|
|
254
|
+
def slow_get_resource_and_dataset(*args, **kwargs):
|
|
255
|
+
time.sleep(10) # well beyond the 2s job timeout
|
|
256
|
+
|
|
257
|
+
self._assert_job_times_out(
|
|
258
|
+
cli, data, "ckanext.xloader.jobs.get_resource_and_dataset",
|
|
259
|
+
slow_get_resource_and_dataset, check_tmp_files=False)
|
|
260
|
+
|
|
225
261
|
@pytest.mark.parametrize("error_type,should_retry", [
|
|
226
262
|
# Retryable errors from RETRYABLE_ERRORS
|
|
227
263
|
("DeadlockDetected", True),
|
|
@@ -1993,3 +1993,99 @@ class TestLoadTabulator(TestLoadBase):
|
|
|
1993
1993
|
u"Citizens Connect App",
|
|
1994
1994
|
),
|
|
1995
1995
|
] # noqa
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
class TestTypeGuessingSampleSize(TestLoadBase):
|
|
1999
|
+
"""ckanext.xloader.type_guessing_sample_size controls how many rows
|
|
2000
|
+
tabulator samples for header and column-type guessing."""
|
|
2001
|
+
|
|
2002
|
+
SETTING = "ckanext.xloader.type_guessing_sample_size"
|
|
2003
|
+
|
|
2004
|
+
def _write_late_text_csv(self, tmp_path, numeric_rows=150):
|
|
2005
|
+
# Column "val" is decimal for the first `numeric_rows` rows, then holds
|
|
2006
|
+
# a text value, then goes back to decimals.
|
|
2007
|
+
lines = ["id,val"]
|
|
2008
|
+
lines += ["{},{}.5".format(i, i) for i in range(numeric_rows)]
|
|
2009
|
+
lines.append("{},N/A".format(numeric_rows))
|
|
2010
|
+
lines += ["{},{}.5".format(i, i) for i in range(numeric_rows + 1, numeric_rows + 50)]
|
|
2011
|
+
path = tmp_path / "late_text.csv"
|
|
2012
|
+
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
2013
|
+
return str(path)
|
|
2014
|
+
|
|
2015
|
+
def test_default_is_100(self):
|
|
2016
|
+
assert loader.DEFAULT_TYPE_GUESSING_SAMPLE_SIZE == 100
|
|
2017
|
+
assert loader.get_type_guessing_sample_size() == 100
|
|
2018
|
+
|
|
2019
|
+
@pytest.mark.parametrize("value, expected", [
|
|
2020
|
+
("1000", 1000),
|
|
2021
|
+
(250, 250),
|
|
2022
|
+
("1", 1),
|
|
2023
|
+
# invalid or non-positive values fall back to the default
|
|
2024
|
+
("abc", 100),
|
|
2025
|
+
("", 100),
|
|
2026
|
+
("0", 100),
|
|
2027
|
+
("-5", 100),
|
|
2028
|
+
("1.5", 100),
|
|
2029
|
+
])
|
|
2030
|
+
def test_get_type_guessing_sample_size(self, ckan_config, monkeypatch,
|
|
2031
|
+
value, expected):
|
|
2032
|
+
monkeypatch.setitem(ckan_config, self.SETTING, value)
|
|
2033
|
+
assert loader.get_type_guessing_sample_size() == expected
|
|
2034
|
+
|
|
2035
|
+
def test_stream_gets_configured_sample_size(self, ckan_config, monkeypatch):
|
|
2036
|
+
monkeypatch.setitem(ckan_config, self.SETTING, "1000")
|
|
2037
|
+
stream = loader.UnknownEncodingStream(
|
|
2038
|
+
"unused.csv", "csv", {"encoding": "utf-8", "confidence": 1.0})
|
|
2039
|
+
assert stream.stream_args["sample_size"] == 1000
|
|
2040
|
+
|
|
2041
|
+
def test_stream_keeps_explicit_sample_size(self, ckan_config, monkeypatch):
|
|
2042
|
+
monkeypatch.setitem(ckan_config, self.SETTING, "1000")
|
|
2043
|
+
stream = loader.UnknownEncodingStream(
|
|
2044
|
+
"unused.csv", "csv", {"encoding": "utf-8", "confidence": 1.0},
|
|
2045
|
+
sample_size=5)
|
|
2046
|
+
assert stream.stream_args["sample_size"] == 5
|
|
2047
|
+
|
|
2048
|
+
def test_load_table_fails_when_text_value_is_beyond_default_sample(
|
|
2049
|
+
self, tmp_path):
|
|
2050
|
+
# The text value is on row 151, past the default sample of 100 rows,
|
|
2051
|
+
# so the column is guessed as numeric and the load fails there.
|
|
2052
|
+
csv_filepath = self._write_late_text_csv(tmp_path)
|
|
2053
|
+
resource = factories.Resource()
|
|
2054
|
+
with pytest.raises(LoaderError):
|
|
2055
|
+
loader.load_table(
|
|
2056
|
+
csv_filepath,
|
|
2057
|
+
resource_id=resource["id"],
|
|
2058
|
+
mimetype="text/csv",
|
|
2059
|
+
logger=logger,
|
|
2060
|
+
)
|
|
2061
|
+
|
|
2062
|
+
def test_load_table_with_larger_sample_guesses_text_column(
|
|
2063
|
+
self, Session, ckan_config, monkeypatch, tmp_path):
|
|
2064
|
+
monkeypatch.setitem(ckan_config, self.SETTING, "1000")
|
|
2065
|
+
csv_filepath = self._write_late_text_csv(tmp_path)
|
|
2066
|
+
resource = factories.Resource()
|
|
2067
|
+
resource_id = resource["id"]
|
|
2068
|
+
loader.load_table(
|
|
2069
|
+
csv_filepath,
|
|
2070
|
+
resource_id=resource_id,
|
|
2071
|
+
mimetype="text/csv",
|
|
2072
|
+
logger=logger,
|
|
2073
|
+
)
|
|
2074
|
+
assert self._get_column_names(Session, resource_id) == [
|
|
2075
|
+
u"_id",
|
|
2076
|
+
u"_full_text",
|
|
2077
|
+
u"id",
|
|
2078
|
+
u"val",
|
|
2079
|
+
]
|
|
2080
|
+
# "val" is text because the sample now includes the "N/A" row.
|
|
2081
|
+
assert self._get_column_types(Session, resource_id) == [
|
|
2082
|
+
u"int4",
|
|
2083
|
+
u"tsvector",
|
|
2084
|
+
u"numeric",
|
|
2085
|
+
u"text",
|
|
2086
|
+
]
|
|
2087
|
+
records = self._get_records(Session, resource_id)
|
|
2088
|
+
assert len(records) == 200
|
|
2089
|
+
assert (151, 150, u"N/A") in [
|
|
2090
|
+
(r[0], int(r[1]), r[2]) for r in records
|
|
2091
|
+
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ckanext-xloader
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.7.0
|
|
4
4
|
Summary: Express Loader - quickly load data into CKAN DataStore
|
|
5
5
|
Author: David Read (davidread), Patricio Del Boca (pdelboca)
|
|
6
6
|
Author-email: ThrawnCA <carl.antuar@smartservice.qld.gov.au>, "Jesse Vickery (JVickery-TBS)" <jesse.vickery@tbs-sct.gc.ca>, "Adrià Mercader (amercader)" <amercadero@gmail.com>, "Brett Jones (kowh-ai)" <datashades@linkdigital.com.au>, "William Dutton (duttonw)" <william.dutton@qld.gov.au>
|
|
@@ -12,12 +12,35 @@ Keywords: CKAN,extension,datastore
|
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
18
|
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.10
|
|
16
20
|
Description-Content-Type: text/markdown
|
|
17
21
|
License-File: LICENSE
|
|
18
22
|
Requires-Dist: typing_extensions
|
|
23
|
+
Requires-Dist: ckantoolkit>=0.0.7
|
|
24
|
+
Requires-Dist: requests>=2.34.2
|
|
25
|
+
Requires-Dist: six>=1.17.0
|
|
26
|
+
Requires-Dist: tabulator==1.53.5
|
|
27
|
+
Requires-Dist: Unidecode==1.4.0
|
|
28
|
+
Requires-Dist: python-dateutil>=2.9.0.post0
|
|
29
|
+
Requires-Dist: certifi>=2026.7.22
|
|
30
|
+
Requires-Dist: chardet==7.6.0
|
|
31
|
+
Requires-Dist: idna>=3.20
|
|
32
|
+
Requires-Dist: urllib3>=2.8.0
|
|
33
|
+
Requires-Dist: zipp>=4.1.0
|
|
19
34
|
Provides-Extra: test
|
|
20
35
|
Requires-Dist: pytest-factoryboy; extra == "test"
|
|
36
|
+
Requires-Dist: responses==0.10.9; extra == "test"
|
|
37
|
+
Requires-Dist: mock==5.2.0; extra == "test"
|
|
38
|
+
Requires-Dist: flake8; extra == "test"
|
|
39
|
+
Requires-Dist: pytest-ckan; extra == "test"
|
|
40
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
41
|
+
Requires-Dist: requests>=2.34.2; extra == "test"
|
|
42
|
+
Requires-Dist: urllib3>=2.8.0; extra == "test"
|
|
43
|
+
Requires-Dist: zipp>=4.1.0; extra == "test"
|
|
21
44
|
Dynamic: license-file
|
|
22
45
|
|
|
23
46
|
# XLoader - ckanext-xloader
|
|
@@ -136,10 +159,10 @@ Compatibility with core CKAN versions:
|
|
|
136
159
|
|
|
137
160
|
| CKAN version | Compatibility |
|
|
138
161
|
|--------------|-------------------------------------------------------|
|
|
139
|
-
| 2.7 | no
|
|
140
|
-
| 2.8 | no
|
|
141
|
-
| 2.9 | no
|
|
142
|
-
| 2.10 | yes
|
|
162
|
+
| 2.7 | no (last supported version: 0.12.2) |
|
|
163
|
+
| 2.8 | no (last supported version: 0.12.2) |
|
|
164
|
+
| 2.9 | no (last supported version: 1.2.x) |
|
|
165
|
+
| 2.10 | yes 3.10+ (python 3.9 last support version: 2.5.1 ) |
|
|
143
166
|
| 2.11 | yes |
|
|
144
167
|
| 2.12 | yes |
|
|
145
168
|
|
|
@@ -396,6 +419,22 @@ If set to 0 (default) files that exceed the `max_content_length` will
|
|
|
396
419
|
not be loaded into the datastore.
|
|
397
420
|
|
|
398
421
|
|
|
422
|
+
#### ckanext.xloader.type_guessing_sample_size
|
|
423
|
+
|
|
424
|
+
Example:
|
|
425
|
+
|
|
426
|
+
```
|
|
427
|
+
ckanext.xloader.type_guessing_sample_size = 1000
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Default value: `100`
|
|
431
|
+
|
|
432
|
+
The number of rows xloader samples from the start of a file to guess
|
|
433
|
+
the header row and the column types. Increase this if values that
|
|
434
|
+
would change a column's type (e.g. decimal numbers) only appear
|
|
435
|
+
further down the file. Larger values use more memory and time.
|
|
436
|
+
|
|
437
|
+
|
|
399
438
|
#### ckanext.xloader.ssl_verify
|
|
400
439
|
|
|
401
440
|
Example:
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
typing_extensions
|
|
2
|
+
ckantoolkit>=0.0.7
|
|
3
|
+
requests>=2.34.2
|
|
4
|
+
six>=1.17.0
|
|
5
|
+
tabulator==1.53.5
|
|
6
|
+
Unidecode==1.4.0
|
|
7
|
+
python-dateutil>=2.9.0.post0
|
|
8
|
+
certifi>=2026.7.22
|
|
9
|
+
chardet==7.6.0
|
|
10
|
+
idna>=3.20
|
|
11
|
+
urllib3>=2.8.0
|
|
12
|
+
zipp>=4.1.0
|
|
13
|
+
|
|
14
|
+
[test]
|
|
15
|
+
pytest-factoryboy
|
|
16
|
+
responses==0.10.9
|
|
17
|
+
mock==5.2.0
|
|
18
|
+
flake8
|
|
19
|
+
pytest-ckan
|
|
20
|
+
pytest-cov
|
|
21
|
+
requests>=2.34.2
|
|
22
|
+
urllib3>=2.8.0
|
|
23
|
+
zipp>=4.1.0
|
|
@@ -4,15 +4,32 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ckanext-xloader"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.7.0"
|
|
8
|
+
requires-python = ">=3.10"
|
|
8
9
|
description = "Express Loader - quickly load data into CKAN DataStore"
|
|
9
10
|
classifiers = [ "Development Status :: 5 - Production/Stable",
|
|
10
11
|
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
|
11
12
|
"Programming Language :: Python :: 3.10",
|
|
13
|
+
"Programming Language :: Python :: 3.11",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
12
16
|
"Programming Language :: Python :: 3.14",
|
|
13
17
|
]
|
|
14
18
|
keywords = [ "CKAN", "extension", "datastore",]
|
|
15
|
-
dependencies = [
|
|
19
|
+
dependencies = [
|
|
20
|
+
"typing_extensions",
|
|
21
|
+
"ckantoolkit>=0.0.7",
|
|
22
|
+
"requests>=2.34.2",
|
|
23
|
+
"six>=1.17.0",
|
|
24
|
+
"tabulator==1.53.5",
|
|
25
|
+
"Unidecode==1.4.0",
|
|
26
|
+
"python-dateutil>=2.9.0.post0",
|
|
27
|
+
"certifi>=2026.7.22",
|
|
28
|
+
"chardet==7.6.0",
|
|
29
|
+
"idna>=3.20",
|
|
30
|
+
"urllib3>=2.8.0",
|
|
31
|
+
"zipp>=4.1.0",
|
|
32
|
+
]
|
|
16
33
|
authors = [
|
|
17
34
|
{name = "ThrawnCA", email = "carl.antuar@smartservice.qld.gov.au"},
|
|
18
35
|
{name = "Jesse Vickery (JVickery-TBS)", email = "jesse.vickery@tbs-sct.gc.ca"},
|
|
@@ -41,7 +58,18 @@ text = "AGPL"
|
|
|
41
58
|
Homepage = "https://github.com/ckan/ckanext-xloader"
|
|
42
59
|
|
|
43
60
|
[project.optional-dependencies]
|
|
44
|
-
test = [
|
|
61
|
+
test = [
|
|
62
|
+
"pytest-factoryboy",
|
|
63
|
+
"responses==0.10.9",
|
|
64
|
+
"mock==5.2.0",
|
|
65
|
+
"flake8",
|
|
66
|
+
"pytest-ckan",
|
|
67
|
+
"pytest-cov",
|
|
68
|
+
"requests>=2.34.2",
|
|
69
|
+
"urllib3>=2.8.0",
|
|
70
|
+
"zipp>=4.1.0"
|
|
71
|
+
]
|
|
72
|
+
|
|
45
73
|
|
|
46
74
|
[project.entry-points."ckan.plugins"]
|
|
47
75
|
xloader = "ckanext.xloader.plugin:xloaderPlugin"
|
|
@@ -71,7 +99,7 @@ filterwarnings = [
|
|
|
71
99
|
]
|
|
72
100
|
|
|
73
101
|
[tool.pyright]
|
|
74
|
-
pythonVersion = "3.
|
|
102
|
+
pythonVersion = "3.10"
|
|
75
103
|
include = ["ckanext"]
|
|
76
104
|
exclude = [
|
|
77
105
|
"**/test*",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
responses==0.26.3
|
|
2
|
-
mock==5.2.0
|
|
3
|
-
flake8
|
|
4
|
-
pytest-ckan
|
|
5
|
-
pytest-cov
|
|
6
|
-
requests>=2.34.2 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
7
|
-
urllib3>=2.8.0 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
8
|
-
zipp>=4.1.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
ckantoolkit>=0.0.7
|
|
2
|
-
requests>=2.34.2
|
|
3
|
-
six>=1.17.0
|
|
4
|
-
tabulator==1.53.5
|
|
5
|
-
Unidecode==1.4.0
|
|
6
|
-
python-dateutil>=2.9.0.post0
|
|
7
|
-
certifi>=2026.7.22 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
8
|
-
chardet==5.2.0
|
|
9
|
-
idna>=3.20 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
10
|
-
urllib3>=2.8.0 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
11
|
-
zipp>=4.1.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/package/resource_read.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext/xloader/templates/xloader/resource_data.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ckanext_xloader-2.5.2 → ckanext_xloader-2.7.0}/ckanext_xloader.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|