Skip to content

Commit

Permalink
ADX-949 patch how ckanext-validation handles foreign keys and their s…
Browse files Browse the repository at this point in the history
…chemas (#105)

feat: patch how ckanext-validation handles foreign keys and their schemas
  • Loading branch information
ChasNelson1990 authored Aug 16, 2023
1 parent b30c222 commit 366fdb5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ckanext/validation/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import ckantoolkit as t
from ckan.plugins import core

from ckanext.scheming.helpers import scheming_get_dataset_schema

from ckanext.validation.model import Validation
from ckanext.validation.utils import get_update_mode_from_config

Expand Down Expand Up @@ -247,8 +249,7 @@ def _prepare_foreign_keys(dataset, schema):
log.debug('Foreign Key resource is (presumably) a resource in this dataset.')

# get the available resources in this dataset
dataset_resources = [{r.get('resource_type'): {'url':r.get('url'), 'format': r.get('format')}} for r in dataset['resources']]
dataset_resources = {k:v for list_item in dataset_resources for (k,v) in list_item.items()}
dataset_resources = {_validation_get_schema(dataset['type'], r.get('resource_type')): {'url':r.get('url'), 'format': r.get('format')} for r in dataset['resources']}

# check foreign key resource is in the dataset and get the url
# if it turns out it isn't we will raise an exception
Expand All @@ -268,6 +269,14 @@ def _prepare_foreign_keys(dataset, schema):
log.debug('Foreign key resources required: ' + str(referenced_resources))
return referenced_resources

def _validation_get_schema(dataset_type, resource_type):
schema = scheming_get_dataset_schema(dataset_type)
for resource in schema.get('resources', []):
if resource.get("resource_type", "") == resource_type:
for field in resource.get('resource_fields', []):
if field['field_name'] == "schema":
return field['field_value']

def _get_site_user_api_key():

site_user_name = t.get_action('get_site_user')({'ignore_auth': True}, {})
Expand Down

0 comments on commit 366fdb5

Please sign in to comment.