Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Extension Support #200

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f0a470a
feat(dev): adds validation extension support;
JVickery-TBS Nov 24, 2023
a97f4ad
feat(dev): logging;
JVickery-TBS Nov 24, 2023
028e42b
fix(dev): 2.9 support;
JVickery-TBS Nov 24, 2023
77d762e
fix(dev): better conditioning;
JVickery-TBS Nov 27, 2023
aec22b9
feat(comments): added comments;
JVickery-TBS Nov 27, 2023
cd3c7cc
Merge branch 'master' into feature/validation-support
JVickery-TBS Jan 29, 2024
7e99aa7
fix(dev): misc feedback;
JVickery-TBS Jan 29, 2024
25ea76e
fix(dev): misc fixes;
JVickery-TBS Jan 29, 2024
d2720fc
fix(syntax): flake8;
JVickery-TBS Jan 31, 2024
e888153
feat(dev): logic and schema config option;
JVickery-TBS Feb 2, 2024
5c07ba4
Merge branch 'master' into feature/validation-support
JVickery-TBS Feb 2, 2024
4612484
feat(dev): better logic and tests;
JVickery-TBS Feb 2, 2024
8ac8db5
fix(logic): fixed some logic;
JVickery-TBS Feb 2, 2024
d9bb56c
Merge branch 'master' into feature/validation-support
JVickery-TBS Feb 5, 2024
1ac8090
fix(syntax): made better;
JVickery-TBS Feb 5, 2024
1761ed5
fix(comments): fixed inline comments;
JVickery-TBS Feb 5, 2024
e182eb7
feat(dev): started doing sync mode;
JVickery-TBS Feb 6, 2024
b386e0e
feat(dev): sync mode cont.;
JVickery-TBS Feb 7, 2024
3200483
feat(dev): sync mode cont.;
JVickery-TBS Feb 7, 2024
d225801
Merge branch 'master' into feature/validation-support
JVickery-TBS May 16, 2024
4fbdb0d
feat(dev): IPipeValidation implementation;
JVickery-TBS May 16, 2024
27d98cf
fix(tests): validation req tests;
JVickery-TBS May 16, 2024
378f69f
fix(misc): comments and messages;
JVickery-TBS Jul 12, 2024
6070740
fix(logic): ignore not sysadmin;
JVickery-TBS Aug 9, 2024
8463a79
feat(misc0: changelog, readme;
JVickery-TBS Dec 9, 2024
f6e577f
Merge branch 'master' into feature/validation-support
JVickery-TBS Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.1.3 2024-12-09
================

Feat:
* Adds support for ckanext-validation. Config `ckanext.xloader.validation.requires_successful_report` controls whether a resource requires a successful validation report to be XLoadered. By default, a resource would also require a Validation Schema, which can be turned off with `ckanext.xloader.validation.enforce_schema`.


**Full Changelog**: https://github.com/ckan/ckanext-xloader/compare/1.1.2...1.1.3

1.1.2 2024-10-25
================

Expand All @@ -21,7 +30,7 @@ Fix:
1.1.0 2024-10-16
================

Fixes:
Fixes:
* feat: Add pypi cicd publish via github action via environment controls by @duttonw in https://github.com/ckan/ckanext-xloader/pull/228


Expand All @@ -32,7 +41,7 @@ Fixes:
================


Fixes:
Fixes:

* add README note about running on separate server, #191 by @ThrawnCA in https://github.com/ckan/ckanext-xloader/pull/192
* Use IDomainObjectModification Implementation by @JVickery-TBS in https://github.com/ckan/ckanext-xloader/pull/198
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Compatibility with core CKAN versions:
| CKAN version | Compatibility |
| -------------- | -------------------------------------------------------------------------------------------------------------- |
| 2.7 | no longer supported (last supported version: 0.12.2) |
| 2.8 | no longer supported (last supported version: 0.12.2) |
| 2.8 | no longer supported (last supported version: 0.12.2) |
| 2.9 | yes (Python3) (last supported version for Python 2.7: 0.12.2)), Must: `pip install "setuptools>=44.1.0,<71"` |
| 2.10 | yes |
| 2.11 | yes |
Expand Down Expand Up @@ -189,7 +189,7 @@ expect European (day-first) dates, you could add to `postgresql.conf`:

datestyle=ISO,DMY

All configurations below are defined in the
All configurations below are defined in the
[config_declaration.yaml](ckanext/xloader/config_declaration.yaml) file.


Expand Down Expand Up @@ -409,6 +409,34 @@ Controls whether or not the status badges display all of the statuses. By defaul
the badges will display "pending", "running", and "error". With debug_badges enabled,
they will also display "complete", "active", "inactive", and "unknown".

#### ckanext.xloader.validation.requires_successful_report

Supports: __ckanext-validation__

Example:

```
ckanext.xloader.validation.requires_successful_report = True
```

Default value: `False`

Controls whether or not a resource requires a successful validation report from the ckanext-validation plugin in order to be XLoadered.

#### ckanext.xloader.validation.enforce_schema

Supports: __ckanext-validation__

Example:

```
ckanext.xloader.validation.enforce_schema = False
```

Default value: `True`

Controls whether or not a resource requires a Validation Schema to be present from the ckanext-validation plugin to be XLoadered.

## Developer installation

To install XLoader for development, activate your CKAN virtualenv and in
Expand Down
18 changes: 15 additions & 3 deletions ckanext/xloader/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def xloader_submit(context, data_dict):
if errors:
raise p.toolkit.ValidationError(errors)

p.toolkit.check_access('xloader_submit', context, data_dict)

# If sync is set to True, the xloader callback will be executed right
# away, instead of a job being enqueued. It will also delete any existing jobs
# for the given resource. This is only controlled by sysadmins or the system.
sync = data_dict.pop('sync', False)

res_id = data_dict['resource_id']
try:
resource_dict = p.toolkit.get_action('resource_show')(context, {
Expand Down Expand Up @@ -166,15 +173,20 @@ def xloader_submit(context, data_dict):
job = enqueue_job(
jobs.xloader_data_into_datastore, [data], queue=custom_queue,
title="xloader_submit: package: {} resource: {}".format(resource_dict.get('package_id'), res_id),
rq_kwargs=dict(timeout=timeout)
rq_kwargs=dict(timeout=timeout, at_front=sync)
duttonw marked this conversation as resolved.
Show resolved Hide resolved
)
except Exception:
log.exception('Unable to enqueued xloader res_id=%s', res_id)
if sync:
log.exception('Unable to xloader res_id=%s', res_id)
else:
log.exception('Unable to enqueue xloader res_id=%s', res_id)
return False
log.debug('Enqueued xloader job=%s res_id=%s', job.id, res_id)

value = json.dumps({'job_id': job.id})

if sync:
log.debug('Pushed xloader sync mode job=%s res_id=%s to front of queue', job.id, res_id)

task['value'] = value
task['state'] = 'pending'
task['last_updated'] = str(datetime.datetime.utcnow())
Expand Down
2 changes: 2 additions & 0 deletions ckanext/xloader/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ groups:
example: False
description: |
Resources are expected to have a Validation Schema, or use the default ones if not.

If this option is set to `False`, Resources that do not have
a Validation Schema will be treated like they do not require Validation.

See https://github.com/frictionlessdata/ckanext-validation?tab=readme-ov-file#data-schema
for more details.
- key: ckanext.xloader.clean_datastore_tables
Expand Down
14 changes: 10 additions & 4 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def before_show(self, resource_dict):
def after_update(self, context, resource_dict):
self.after_resource_update(context, resource_dict)

def _submit_to_xloader(self, resource_dict):
def _submit_to_xloader(self, resource_dict, sync=False):
context = {"ignore_auth": True, "defer_commit": True}
resource_format = resource_dict.get("format")
if not XLoaderFormats.is_it_an_xloader_format(resource_format):
Expand All @@ -203,14 +203,20 @@ def _submit_to_xloader(self, resource_dict):
return

try:
log.debug(
"Submitting resource %s to be xloadered", resource_dict["id"]
)
if sync:
log.debug(
"xloadering resource %s in sync mode", resource_dict["id"]
)
else:
log.debug(
"Submitting resource %s to be xloadered", resource_dict["id"]
)
toolkit.get_action("xloader_submit")(
context,
{
"resource_id": resource_dict["id"],
"ignore_hash": self.ignore_hash,
"sync": sync,
},
)
except toolkit.ValidationError as e:
Expand Down
2 changes: 2 additions & 0 deletions ckanext/xloader/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
boolean_validator = get_validator('boolean_validator')
int_validator = get_validator('int_validator')
OneOf = get_validator('OneOf')
ignore_not_sysadmin = get_validator('ignore_not_sysadmin')
duttonw marked this conversation as resolved.
Show resolved Hide resolved

if p.toolkit.check_ckan_version('2.9'):
unicode_safe = get_validator('unicode_safe')
Expand All @@ -29,6 +30,7 @@ def xloader_submit_schema():
'id': [ignore_missing],
'set_url_type': [ignore_missing, boolean_validator],
'ignore_hash': [ignore_missing, boolean_validator],
'sync': [ignore_missing, boolean_validator, ignore_not_sysadmin],
'__junk': [empty],
'__before': [dsschema.rename('id', 'resource_id')]
}
Expand Down
7 changes: 4 additions & 3 deletions ckanext/xloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import datetime
from rq import get_current_job

from six import text_type as str, binary_type

Expand Down Expand Up @@ -33,8 +34,6 @@
"application/vnd.oasis.opendocument.spreadsheet",
]

from .job_exceptions import JobError


class XLoaderFormats(object):
formats = None
Expand All @@ -61,8 +60,10 @@ def awaiting_validation(res_dict):
"""
Checks the existence of a logic action from the ckanext-validation
plugin, thus supporting any extending of the Validation Plugin class.

Checks ckanext.xloader.validation.requires_successful_report config
option value.

Checks ckanext.xloader.validation.enforce_schema config
option value. Then checks the Resource's validation_status.
"""
Expand Down Expand Up @@ -273,7 +274,7 @@ def type_guess(rows, types=TYPES, strict=False):
at_least_one_value = []
for ri, row in enumerate(rows):
diff = len(row) - len(guesses)
for _ in range(diff):
for _i in range(diff):
typesdict = {}
for type in types:
typesdict[type] = 0
Expand Down
Loading