Skip to content

Commit

Permalink
feat(dev): enforce schema;
Browse files Browse the repository at this point in the history
- New config option to enforce validation schema existing.
- Renamed config options.
  • Loading branch information
JVickery-TBS committed Feb 2, 2024
1 parent f493dbb commit e2a5aeb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
16 changes: 8 additions & 8 deletions ckanext/xloader/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,24 @@ groups:
to True.
type: bool
required: false
- key: ckanext.xloader.validation.requiredSoWaitForReport
- key: ckanext.xloader.validation.requires_successful_report
default: False
example: True
description: |
Resources are required to pass validation from the ckanext-validation
plugin to be able to get xloadered.
Resources are required to pass Validation from the ckanext-validation
plugin to be able to get XLoadered.
type: bool
required: false
- key: ckanext.xloader.validation.enforceDefaultsIfSchemaMissing
- key: ckanext.xloader.validation.enforce_schema
default: True
example: False
description: |
Resources are required to have a Schema including the field `validation_status`.
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_status` field will
always be submitted to XLoader.
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#changes-in-the-metadata-schema
See https://github.com/frictionlessdata/ckanext-validation?tab=readme-ov-file#data-schema
for more details.
type: bool
required: false
Expand Down
28 changes: 12 additions & 16 deletions ckanext/xloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ 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.requiredSoWaitForReport config
Checks ckanext.xloader.validation.requires_successful_report config
option value.
Checks ckanext.xloader.validation.enforceDefaultsIfSchemaMissing config
option value. Then checks the Resource's Schema for the `validation_status` field.
Checks ckanext.xloader.validation.enforce_schema config
option value. Then checks the Resource's validation_status.
"""
if not p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.requiredSoWaitForReport', False)):
# validation.requiredSoWaitForReport is turned off, return right away
if not p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.requires_successful_report', False)):
# validation.requires_successful_report is turned off, return right away
return False

try:
Expand All @@ -72,22 +72,18 @@ def awaiting_validation(res_dict):

if not is_validation_plugin_loaded:
# the validation plugin is not loaded but required, log a warning
log.warning('ckanext.xloader.validation.requiredSoWaitForReport requires the ckanext-validation plugin to be activated.')
log.warning('ckanext.xloader.validation.requires_successful_report requires the ckanext-validation plugin to be activated.')
return False

if p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.enforceDefaultsIfSchemaMissing', True)):
# validation.enforceDefaultsIfSchemaMissing is turned on, so we will expect Resources to have `validation_status`
if p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.enforce_schema', True)):
# validation.enforce_schema is turned on, so we will always look for `validation_status`
if res_dict.get('validation_status', None) != 'success':
return True
else:
return False
else:
# TODO: check the Resource's schema to see if there is no `validation_status`,
# if there is not, then return False, otherwise check if it is `success` or not.
# default_resource_schema ??
return True

return True
# validation.enforce_schema is turned off, so if the Resource
# does not have a Validation Schema, we will treat it like
# it does not require Validation.
return False


def resource_data(id, resource_id, rows=None):
Expand Down

0 comments on commit e2a5aeb

Please sign in to comment.