ckanext-xloader 2.3.1__tar.gz → 2.4.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.3.1/ckanext_xloader.egg-info → ckanext_xloader-2.4.0}/PKG-INFO +10 -8
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/README.md +8 -7
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/db.py +14 -9
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/jobs.py +4 -3
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/loader.py +12 -12
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_action.py +11 -4
- ckanext_xloader-2.4.0/ckanext/xloader/tests/test_db.py +106 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_jobs.py +17 -2
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/utils.py +8 -4
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0/ckanext_xloader.egg-info}/PKG-INFO +10 -8
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/SOURCES.txt +1 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/pyproject.toml +4 -2
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/CHANGELOG +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/LICENSE +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/MANIFEST.in +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/__init__.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/__init__.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/action.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/auth.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/cli.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/command.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/config_declaration.yaml +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/helpers.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/interfaces.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/job_exceptions.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/parser.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/plugin.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/schema.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/datastore/snippets/dictionary_form.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/resource_edit_base.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/resource_read.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resource_info.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resource_item.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/package/snippets/resources.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/xloader/confirm_datastore_delete.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/templates/xloader/resource_data.html +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/__init__.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/ckan_setup.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/fixtures.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_chunks.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_loader.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_parser.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_plugin.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/tests/test_utils.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/views.py +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/webassets/css/xloader.css +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext/xloader/webassets/webassets.yml +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/dependency_links.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/entry_points.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/requires.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/top_level.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/dev-requirements.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/requirements.txt +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/setup.cfg +0 -0
- {ckanext_xloader-2.3.1 → ckanext_xloader-2.4.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.4.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>
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.7
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.8
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
19
|
Description-Content-Type: text/markdown
|
|
19
20
|
License-File: LICENSE
|
|
20
21
|
Requires-Dist: typing_extensions
|
|
@@ -136,13 +137,14 @@ type -offers to contribute this are welcomed.
|
|
|
136
137
|
|
|
137
138
|
Compatibility with core CKAN versions:
|
|
138
139
|
|
|
139
|
-
| CKAN version
|
|
140
|
-
|
|
141
|
-
| 2.7
|
|
142
|
-
| 2.8
|
|
143
|
-
| 2.9
|
|
144
|
-
| 2.10
|
|
145
|
-
| 2.11
|
|
140
|
+
| CKAN version | Compatibility |
|
|
141
|
+
|--------------|-------------------------------------------------------|
|
|
142
|
+
| 2.7 | no longer supported (last supported version: 0.12.2) |
|
|
143
|
+
| 2.8 | no longer supported (last supported version: 0.12.2) |
|
|
144
|
+
| 2.9 | no longer supported (last supported version: 1.2.x) |
|
|
145
|
+
| 2.10 | yes |
|
|
146
|
+
| 2.11 | yes |
|
|
147
|
+
| 2.12 | yes |
|
|
146
148
|
|
|
147
149
|
## Installation
|
|
148
150
|
|
|
@@ -112,13 +112,14 @@ type -offers to contribute this are welcomed.
|
|
|
112
112
|
|
|
113
113
|
Compatibility with core CKAN versions:
|
|
114
114
|
|
|
115
|
-
| CKAN version
|
|
116
|
-
|
|
117
|
-
| 2.7
|
|
118
|
-
| 2.8
|
|
119
|
-
| 2.9
|
|
120
|
-
| 2.10
|
|
121
|
-
| 2.11
|
|
115
|
+
| CKAN version | Compatibility |
|
|
116
|
+
|--------------|-------------------------------------------------------|
|
|
117
|
+
| 2.7 | no longer supported (last supported version: 0.12.2) |
|
|
118
|
+
| 2.8 | no longer supported (last supported version: 0.12.2) |
|
|
119
|
+
| 2.9 | no longer supported (last supported version: 1.2.x) |
|
|
120
|
+
| 2.10 | yes |
|
|
121
|
+
| 2.11 | yes |
|
|
122
|
+
| 2.12 | yes |
|
|
122
123
|
|
|
123
124
|
## Installation
|
|
124
125
|
|
|
@@ -11,7 +11,6 @@ import json
|
|
|
11
11
|
import six
|
|
12
12
|
import sqlalchemy
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
ENGINE = None
|
|
16
15
|
_METADATA = None
|
|
17
16
|
JOBS_TABLE = None
|
|
@@ -111,17 +110,19 @@ def get_job(job_id):
|
|
|
111
110
|
if job_id:
|
|
112
111
|
job_id = six.text_type(job_id)
|
|
113
112
|
|
|
113
|
+
if JOBS_TABLE is None or ENGINE is None:
|
|
114
|
+
raise RuntimeError("DB is not initialized")
|
|
115
|
+
|
|
116
|
+
stmt = sqlalchemy.select(JOBS_TABLE).where(JOBS_TABLE.c.job_id == job_id)
|
|
114
117
|
with ENGINE.connect() as conn:
|
|
115
|
-
result = conn.execute(
|
|
116
|
-
JOBS_TABLE.select().where(JOBS_TABLE.c.job_id == job_id)
|
|
117
|
-
).first()
|
|
118
|
+
result = conn.execute(stmt).first()
|
|
118
119
|
|
|
119
120
|
if not result:
|
|
120
121
|
return None
|
|
121
122
|
|
|
122
123
|
# Turn the result into a dictionary representation of the job.
|
|
123
124
|
result_dict = {}
|
|
124
|
-
for field in
|
|
125
|
+
for field in stmt.columns.keys():
|
|
125
126
|
value = getattr(result, field)
|
|
126
127
|
if value is None:
|
|
127
128
|
result_dict[field] = value
|
|
@@ -445,6 +446,8 @@ def _get_metadata(job_id):
|
|
|
445
446
|
# Avoid SQLAlchemy "Unicode type received non-unicode bind param value"
|
|
446
447
|
# warnings.
|
|
447
448
|
job_id = six.text_type(job_id)
|
|
449
|
+
if ENGINE is None or METADATA_TABLE is None:
|
|
450
|
+
raise RuntimeError("DB is not initialized")
|
|
448
451
|
|
|
449
452
|
with ENGINE.connect() as conn:
|
|
450
453
|
results = conn.execute(
|
|
@@ -452,10 +455,10 @@ def _get_metadata(job_id):
|
|
|
452
455
|
METADATA_TABLE.c.job_id == job_id)).fetchall()
|
|
453
456
|
metadata = {}
|
|
454
457
|
for row in results:
|
|
455
|
-
value = row
|
|
456
|
-
if row
|
|
458
|
+
value = row.value
|
|
459
|
+
if row.type == 'json':
|
|
457
460
|
value = json.loads(value)
|
|
458
|
-
metadata[row
|
|
461
|
+
metadata[row.key] = value
|
|
459
462
|
return metadata
|
|
460
463
|
|
|
461
464
|
|
|
@@ -464,12 +467,14 @@ def _get_logs(job_id):
|
|
|
464
467
|
# Avoid SQLAlchemy "Unicode type received non-unicode bind param value"
|
|
465
468
|
# warnings.
|
|
466
469
|
job_id = six.text_type(job_id)
|
|
470
|
+
if ENGINE is None or LOGS_TABLE is None:
|
|
471
|
+
raise RuntimeError("DB is not initialized")
|
|
467
472
|
|
|
468
473
|
with ENGINE.connect() as conn:
|
|
469
474
|
results = conn.execute(
|
|
470
475
|
LOGS_TABLE.select().where(LOGS_TABLE.c.job_id == job_id)).fetchall()
|
|
471
476
|
|
|
472
|
-
results = [dict(result) for result in results]
|
|
477
|
+
results = [dict(result._mapping) for result in results] # pyright: ignore[reportPrivateUsage]
|
|
473
478
|
|
|
474
479
|
for result in results:
|
|
475
480
|
result.pop("job_id")
|
|
@@ -136,7 +136,6 @@ def xloader_data_into_datastore(input):
|
|
|
136
136
|
|
|
137
137
|
job_id = get_current_job().id
|
|
138
138
|
errored = False
|
|
139
|
-
|
|
140
139
|
# Set-up logging to the db
|
|
141
140
|
handler = StoringHandler(job_id, input)
|
|
142
141
|
level = logging.DEBUG
|
|
@@ -149,6 +148,7 @@ def xloader_data_into_datastore(input):
|
|
|
149
148
|
logger.setLevel(logging.DEBUG)
|
|
150
149
|
|
|
151
150
|
db.init(config)
|
|
151
|
+
|
|
152
152
|
try:
|
|
153
153
|
# Store details of the job in the db
|
|
154
154
|
db.add_pending_job(job_id, **input)
|
|
@@ -159,13 +159,14 @@ def xloader_data_into_datastore(input):
|
|
|
159
159
|
db.mark_job_as_errored(job_id, str(e))
|
|
160
160
|
job_dict['status'] = 'error'
|
|
161
161
|
job_dict['error'] = str(e)
|
|
162
|
-
|
|
162
|
+
logger.error('xloader error: job_id %s already exists', job_id)
|
|
163
163
|
errored = True
|
|
164
164
|
except Exception as e:
|
|
165
165
|
error_state = {'errored': errored}
|
|
166
166
|
retry = handle_retryable_error(e, input, job_id, job_dict, logger, error_state)
|
|
167
167
|
if retry:
|
|
168
168
|
return None
|
|
169
|
+
logger.error('xloader error: %s', e)
|
|
169
170
|
errored = error_state['errored']
|
|
170
171
|
finally:
|
|
171
172
|
# job_dict is defined in xloader_hook's docstring
|
|
@@ -656,7 +657,7 @@ class StoringHandler(logging.Handler):
|
|
|
656
657
|
self.input = input
|
|
657
658
|
|
|
658
659
|
def emit(self, record):
|
|
659
|
-
with db.ENGINE.
|
|
660
|
+
with db.ENGINE.begin() as conn:
|
|
660
661
|
# Turn strings into unicode to stop SQLAlchemy
|
|
661
662
|
# "Unicode type received non-unicode bind param value" warnings.
|
|
662
663
|
message = str(record.getMessage())
|
|
@@ -259,8 +259,7 @@ def split_copy_by_size(input_file, engine, logger, resource_id, headers, delimit
|
|
|
259
259
|
|
|
260
260
|
logger.info('Completed chunked processing: %s chunks processed for file size %s bytes', chunk_count, file_size)
|
|
261
261
|
if infile:
|
|
262
|
-
infile
|
|
263
|
-
os.remove(infile.name)
|
|
262
|
+
cleanup_temp_file(infile)
|
|
264
263
|
|
|
265
264
|
|
|
266
265
|
def _read_metadata(table_filepath, mimetype, logger):
|
|
@@ -440,7 +439,9 @@ def load_csv(csv_filepath, resource_id, mimetype='text/csv', allow_type_guessing
|
|
|
440
439
|
|
|
441
440
|
# Create table
|
|
442
441
|
from ckan import model
|
|
443
|
-
|
|
442
|
+
|
|
443
|
+
user = p.toolkit.get_action("get_site_user")({"ignore_auth": True}, {})
|
|
444
|
+
context = {'model': model, 'ignore_auth': True, "user": user["name"]}
|
|
444
445
|
data_dict = dict(
|
|
445
446
|
resource_id=resource_id,
|
|
446
447
|
fields=fields,
|
|
@@ -777,10 +778,9 @@ def _enable_fulltext_trigger(connection, resource_id):
|
|
|
777
778
|
|
|
778
779
|
|
|
779
780
|
def _get_rows_count_of_resource(connection, table):
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
rows_count
|
|
783
|
-
return rows_count
|
|
781
|
+
tbl = sa.table(table, sa.column("_id"))
|
|
782
|
+
rows_count = connection.scalar(sa.select(sa.func.count(tbl.c._id)).select_from(tbl))
|
|
783
|
+
return rows_count or 0
|
|
784
784
|
|
|
785
785
|
|
|
786
786
|
def _populate_fulltext(connection, resource_id, fields, logger):
|
|
@@ -814,7 +814,7 @@ def _populate_fulltext(connection, resource_id, fields, logger):
|
|
|
814
814
|
'''
|
|
815
815
|
try:
|
|
816
816
|
# Get total row count to determine chunking strategy
|
|
817
|
-
rows_count = _get_rows_count_of_resource(connection,
|
|
817
|
+
rows_count = _get_rows_count_of_resource(connection, resource_id)
|
|
818
818
|
except Exception as e:
|
|
819
819
|
rows_count = ''
|
|
820
820
|
logger.info("Failed to get resource rows count: {} ".format(str(e)))
|
|
@@ -830,7 +830,7 @@ def _populate_fulltext(connection, resource_id, fields, logger):
|
|
|
830
830
|
for start in range(0, rows_count, chunks):
|
|
831
831
|
try:
|
|
832
832
|
# Build SQL to update _full_text column with concatenated searchable content
|
|
833
|
-
sql =
|
|
833
|
+
sql = sa.text(
|
|
834
834
|
'''
|
|
835
835
|
UPDATE {table}
|
|
836
836
|
SET _full_text = to_tsvector({cols}) WHERE _id BETWEEN {first} and {end};
|
|
@@ -848,7 +848,7 @@ def _populate_fulltext(connection, resource_id, fields, logger):
|
|
|
848
848
|
),
|
|
849
849
|
first=start,
|
|
850
850
|
end=start + chunks
|
|
851
|
-
)
|
|
851
|
+
))
|
|
852
852
|
connection.execute(sql)
|
|
853
853
|
logger.info("Indexed rows {first} to {end} of {total}".format(
|
|
854
854
|
first=start, end=min(start + chunks, rows_count), total=rows_count))
|
|
@@ -866,8 +866,8 @@ def calculate_record_count(resource_id, logger):
|
|
|
866
866
|
'''
|
|
867
867
|
logger.info('Calculating record count (running ANALYZE on the table)')
|
|
868
868
|
engine = get_write_engine()
|
|
869
|
-
|
|
870
|
-
|
|
869
|
+
with engine.connect() as conn:
|
|
870
|
+
conn.execute(sa.text("ANALYZE \"{resource_id}\";"
|
|
871
871
|
.format(resource_id=resource_id)))
|
|
872
872
|
|
|
873
873
|
|
|
@@ -11,11 +11,18 @@ from ckan.tests import helpers, factories
|
|
|
11
11
|
from ckanext.xloader.utils import get_xloader_user_apitoken
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
@pytest.fixture
|
|
15
|
+
def with_api_token(monkeypatch, ckan_config):
|
|
16
|
+
sysadmin = factories.SysadminWithToken()
|
|
17
|
+
apikey = sysadmin["token"]
|
|
18
|
+
monkeypatch.setitem(ckan_config, 'ckanext.xloader.api_token', apikey)
|
|
19
|
+
|
|
20
|
+
|
|
14
21
|
@pytest.mark.usefixtures("clean_db", "with_plugins")
|
|
15
22
|
@pytest.mark.ckan_config("ckan.plugins", "datastore xloader")
|
|
16
23
|
class TestAction(object):
|
|
17
24
|
|
|
18
|
-
def test_submit(self):
|
|
25
|
+
def test_submit(self, with_api_token):
|
|
19
26
|
# checks that xloader_submit enqueues the resource (to be xloadered)
|
|
20
27
|
user = factories.User()
|
|
21
28
|
# normally creating a resource causes xloader_submit to be called,
|
|
@@ -34,7 +41,7 @@ class TestAction(object):
|
|
|
34
41
|
assert 1 == enqueue_mock.call_count
|
|
35
42
|
assert enqueue_mock.call_args[1].get('queue') == 'default{}'.format(ord(res['package_id'][0]) % 2)
|
|
36
43
|
|
|
37
|
-
def test_submit_nonexistent_resource(self):
|
|
44
|
+
def test_submit_nonexistent_resource(self, with_api_token):
|
|
38
45
|
user = factories.User()
|
|
39
46
|
with mock.patch(
|
|
40
47
|
"ckanext.xloader.action.enqueue_job",
|
|
@@ -66,7 +73,7 @@ class TestAction(object):
|
|
|
66
73
|
queue='foo',
|
|
67
74
|
) is True
|
|
68
75
|
|
|
69
|
-
def test_duplicated_submits(self):
|
|
76
|
+
def test_duplicated_submits(self, with_api_token):
|
|
70
77
|
def submit(res, user):
|
|
71
78
|
return helpers.call_action(
|
|
72
79
|
"xloader_submit",
|
|
@@ -121,7 +128,7 @@ class TestAction(object):
|
|
|
121
128
|
)
|
|
122
129
|
assert task_status["state"] == "complete"
|
|
123
130
|
|
|
124
|
-
def test_status(self):
|
|
131
|
+
def test_status(self, with_api_token):
|
|
125
132
|
|
|
126
133
|
# Trigger an xloader job
|
|
127
134
|
res = factories.Resource(format="CSV")
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from faker import Faker
|
|
9
|
+
|
|
10
|
+
from ckanext.xloader import db, jobs
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.mark.usefixtures("with_plugins", "clean_db")
|
|
14
|
+
class TestGetJob:
|
|
15
|
+
@pytest.fixture(autouse=True)
|
|
16
|
+
def init(self, ckan_config: dict[str, Any]):
|
|
17
|
+
db.init(ckan_config)
|
|
18
|
+
# tables may persist across test sessions. Remove old records to
|
|
19
|
+
# prevent UNIQUE job_id errors.
|
|
20
|
+
with db.ENGINE.begin() as conn:
|
|
21
|
+
conn.execute(sa.delete(db.JOBS_TABLE))
|
|
22
|
+
conn.execute(sa.delete(db.METADATA_TABLE))
|
|
23
|
+
conn.execute(sa.delete(db.LOGS_TABLE))
|
|
24
|
+
|
|
25
|
+
def test_jobs_table_not_initialized(
|
|
26
|
+
self, faker: Faker, monkeypatch: pytest.MonkeyPatch
|
|
27
|
+
):
|
|
28
|
+
"""When jobs table is not initialized, get_job raises a RuntimeError."""
|
|
29
|
+
monkeypatch.setattr(db, "JOBS_TABLE", None)
|
|
30
|
+
with pytest.raises(RuntimeError):
|
|
31
|
+
db.get_job(faker.uuid4())
|
|
32
|
+
|
|
33
|
+
def test_metadata_table_not_initialized(
|
|
34
|
+
self, faker: Faker, monkeypatch: pytest.MonkeyPatch
|
|
35
|
+
):
|
|
36
|
+
"""When metadata table is not initialized, get_job raises a RuntimeError.
|
|
37
|
+
|
|
38
|
+
This should not happen normally, but since we are using global
|
|
39
|
+
variables, there is always a chance that somebody hacks things in a
|
|
40
|
+
wrong way and we must react properly.
|
|
41
|
+
"""
|
|
42
|
+
id = faker.uuid4()
|
|
43
|
+
db.add_pending_job(id, "test", "123")
|
|
44
|
+
|
|
45
|
+
monkeypatch.setattr(db, "METADATA_TABLE", None)
|
|
46
|
+
with pytest.raises(RuntimeError):
|
|
47
|
+
db.get_job(id)
|
|
48
|
+
|
|
49
|
+
def test_logs_table_not_initialized(
|
|
50
|
+
self, faker: Faker, monkeypatch: pytest.MonkeyPatch
|
|
51
|
+
):
|
|
52
|
+
"""When logs table is not initialized, get_job raises a RuntimeError.
|
|
53
|
+
|
|
54
|
+
This should not happen normally, but since we are using global
|
|
55
|
+
variables, there is always a chance that somebody hacks things in a
|
|
56
|
+
wrong way and we must react properly.
|
|
57
|
+
"""
|
|
58
|
+
id = faker.uuid4()
|
|
59
|
+
db.add_pending_job(id, "test", "123")
|
|
60
|
+
|
|
61
|
+
monkeypatch.setattr(db, "LOGS_TABLE", None)
|
|
62
|
+
with pytest.raises(RuntimeError):
|
|
63
|
+
db.get_job(id)
|
|
64
|
+
|
|
65
|
+
def test_initialized(self, faker: Faker):
|
|
66
|
+
"""get_job returns None for a non-existent job."""
|
|
67
|
+
job = db.get_job(faker.uuid4())
|
|
68
|
+
assert job is None
|
|
69
|
+
|
|
70
|
+
def test_existing(self, faker: Faker):
|
|
71
|
+
"""get_job returns a job dict for an existing job."""
|
|
72
|
+
id = faker.uuid4()
|
|
73
|
+
metadata = faker.pydict(value_types=(int, str))
|
|
74
|
+
|
|
75
|
+
db.add_pending_job(id, "test", "123", metadata=metadata)
|
|
76
|
+
|
|
77
|
+
job = db.get_job(id)
|
|
78
|
+
assert job
|
|
79
|
+
assert job["job_type"] == "test"
|
|
80
|
+
assert job["metadata"] == metadata
|
|
81
|
+
|
|
82
|
+
def test_logs(self, faker: Faker):
|
|
83
|
+
"""get_job returns logs for an existing job, if there are any."""
|
|
84
|
+
id = faker.uuid4()
|
|
85
|
+
db.add_pending_job(id, "test", "123")
|
|
86
|
+
job = db.get_job(id)
|
|
87
|
+
assert not job["logs"]
|
|
88
|
+
|
|
89
|
+
handler = jobs.StoringHandler(id, {})
|
|
90
|
+
handler.setLevel(logging.DEBUG)
|
|
91
|
+
logger = logging.getLogger(id)
|
|
92
|
+
logger.setLevel(logging.DEBUG)
|
|
93
|
+
logger.addHandler(handler)
|
|
94
|
+
|
|
95
|
+
first_message = faker.sentence()
|
|
96
|
+
second_message = faker.sentence()
|
|
97
|
+
|
|
98
|
+
logger.info(first_message)
|
|
99
|
+
logger.info(second_message)
|
|
100
|
+
|
|
101
|
+
job = db.get_job(id)
|
|
102
|
+
assert len(job["logs"]) == 2
|
|
103
|
+
|
|
104
|
+
messages = sorted([item["message"] for item in job["logs"]])
|
|
105
|
+
|
|
106
|
+
assert messages == sorted([first_message, second_message])
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from collections import namedtuple
|
|
4
|
+
from typing import Any
|
|
3
5
|
import pytest
|
|
4
6
|
import io
|
|
5
7
|
import os
|
|
6
8
|
|
|
7
9
|
from datetime import datetime
|
|
8
10
|
|
|
11
|
+
from faker import Faker
|
|
9
12
|
from requests import Response
|
|
10
13
|
|
|
11
14
|
from ckan.cli.cli import ckan
|
|
@@ -88,12 +91,23 @@ def data(create_with_upload, apikey):
|
|
|
88
91
|
@pytest.mark.ckan_config("ckanext.xloader.copy_chunk_size", 5120)
|
|
89
92
|
@pytest.mark.ckan_config("ckan.jobs.timeout", 2)
|
|
90
93
|
class TestXLoaderJobs(helpers.FunctionalRQTestBase):
|
|
91
|
-
|
|
92
94
|
def test_derive_queue_name(self):
|
|
93
95
|
assert jobs.get_default_queue_name() == "default0"
|
|
94
96
|
assert jobs.get_default_queue_name("foo") == "default0"
|
|
95
97
|
assert jobs.get_default_queue_name("meh") == "default1"
|
|
96
98
|
|
|
99
|
+
def test_job_duplicate(self, data: dict[str, Any], monkeypatch: pytest.MonkeyPatch, faker: Faker):
|
|
100
|
+
job = namedtuple("Job", ["id"])(id=faker.uuid4())
|
|
101
|
+
stub = mock.Mock()
|
|
102
|
+
monkeypatch.setattr(jobs, "get_current_job", lambda: job)
|
|
103
|
+
monkeypatch.setattr(jobs, "callback_xloader_hook", stub)
|
|
104
|
+
jobs.xloader_data_into_datastore(data)
|
|
105
|
+
jobs.xloader_data_into_datastore(data)
|
|
106
|
+
|
|
107
|
+
job_dict = stub.call_args.kwargs["job_dict"]
|
|
108
|
+
assert job_dict["status"] == "error"
|
|
109
|
+
assert "UNIQUE" in job_dict["error"]
|
|
110
|
+
|
|
97
111
|
def test_xloader_data_into_datastore(self, cli, data):
|
|
98
112
|
self.enqueue(jobs.xloader_data_into_datastore, [data])
|
|
99
113
|
with mock.patch("ckanext.xloader.jobs.get_response", get_response):
|
|
@@ -232,6 +246,7 @@ class TestXLoaderJobs(helpers.FunctionalRQTestBase):
|
|
|
232
246
|
("ValueError", False),
|
|
233
247
|
("TypeError", False),
|
|
234
248
|
])
|
|
249
|
+
@pytest.mark.usefixtures("with_extended_cli")
|
|
235
250
|
def test_retry_behavior(self, cli, data, error_type, should_retry):
|
|
236
251
|
"""Test retry behavior for different error types."""
|
|
237
252
|
|
|
@@ -241,9 +241,14 @@ def set_resource_metadata(update_dict):
|
|
|
241
241
|
|
|
242
242
|
Called after creation or deletion of DataStore table.
|
|
243
243
|
'''
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
if tk.check_ckan_version(min_version="2.11.99"):
|
|
245
|
+
# ckan v2.12 has optimized resource updates that skip validation for
|
|
246
|
+
# the rest of dataset resources, so using update/patch here will be
|
|
247
|
+
# more readable.
|
|
248
|
+
user = tk.get_action("get_site_user")({"ignore_auth": True}, {})
|
|
249
|
+
patch = dict(update_dict, id=update_dict["resource_id"])
|
|
250
|
+
tk.get_action("resource_patch")({"user": user["name"]}, patch)
|
|
251
|
+
return
|
|
247
252
|
|
|
248
253
|
q = model.Session.query(model.Resource). \
|
|
249
254
|
with_for_update(of=model.Resource). \
|
|
@@ -276,7 +281,6 @@ def set_resource_metadata(update_dict):
|
|
|
276
281
|
psi.index_package(solr_data_dict)
|
|
277
282
|
break
|
|
278
283
|
|
|
279
|
-
|
|
280
284
|
def column_count_modal(rows):
|
|
281
285
|
""" Return the modal value of columns in the row_set's
|
|
282
286
|
sample. This can be assumed to be the number of columns
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ckanext-xloader
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.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>
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.7
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.8
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
19
|
Description-Content-Type: text/markdown
|
|
19
20
|
License-File: LICENSE
|
|
20
21
|
Requires-Dist: typing_extensions
|
|
@@ -136,13 +137,14 @@ type -offers to contribute this are welcomed.
|
|
|
136
137
|
|
|
137
138
|
Compatibility with core CKAN versions:
|
|
138
139
|
|
|
139
|
-
| CKAN version
|
|
140
|
-
|
|
141
|
-
| 2.7
|
|
142
|
-
| 2.8
|
|
143
|
-
| 2.9
|
|
144
|
-
| 2.10
|
|
145
|
-
| 2.11
|
|
140
|
+
| CKAN version | Compatibility |
|
|
141
|
+
|--------------|-------------------------------------------------------|
|
|
142
|
+
| 2.7 | no longer supported (last supported version: 0.12.2) |
|
|
143
|
+
| 2.8 | no longer supported (last supported version: 0.12.2) |
|
|
144
|
+
| 2.9 | no longer supported (last supported version: 1.2.x) |
|
|
145
|
+
| 2.10 | yes |
|
|
146
|
+
| 2.11 | yes |
|
|
147
|
+
| 2.12 | yes |
|
|
146
148
|
|
|
147
149
|
## Installation
|
|
148
150
|
|
|
@@ -38,6 +38,7 @@ ckanext/xloader/tests/ckan_setup.py
|
|
|
38
38
|
ckanext/xloader/tests/fixtures.py
|
|
39
39
|
ckanext/xloader/tests/test_action.py
|
|
40
40
|
ckanext/xloader/tests/test_chunks.py
|
|
41
|
+
ckanext/xloader/tests/test_db.py
|
|
41
42
|
ckanext/xloader/tests/test_jobs.py
|
|
42
43
|
ckanext/xloader/tests/test_loader.py
|
|
43
44
|
ckanext/xloader/tests/test_parser.py
|
|
@@ -4,14 +4,16 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ckanext-xloader"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.4.0"
|
|
8
8
|
description = "Express Loader - quickly load data into CKAN DataStore"
|
|
9
9
|
classifiers = [ "Development Status :: 5 - Production/Stable",
|
|
10
10
|
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
|
11
11
|
"Programming Language :: Python :: 3.7",
|
|
12
12
|
"Programming Language :: Python :: 3.8",
|
|
13
13
|
"Programming Language :: Python :: 3.9",
|
|
14
|
-
"Programming Language :: Python :: 3.10",
|
|
14
|
+
"Programming Language :: Python :: 3.10",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
]
|
|
15
17
|
keywords = [ "CKAN", "extension", "datastore",]
|
|
16
18
|
dependencies = [ "typing_extensions",]
|
|
17
19
|
authors = [
|
|
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.3.1 → ckanext_xloader-2.4.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.3.1 → ckanext_xloader-2.4.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
|
{ckanext_xloader-2.3.1 → ckanext_xloader-2.4.0}/ckanext_xloader.egg-info/dependency_links.txt
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
|