Skip to content

Commit 23b2db1

Browse files
committed
feat(logic): macth scheam fields;
- Check for old non-schema fields.
1 parent 536933f commit 23b2db1

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

ckanext/recombinant/logic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def recombinant_show(context: Context, data_dict: DataDict) -> Dict[str, Any]:
120120
limit=0)
121121
datastore_correct = _datastore_match(r['fields'], ds['fields'])
122122
out['datastore_correct'] = datastore_correct
123+
schema_correct = _schema_match(r['fields'], ds['fields'])
124+
out['schema_correct'] = schema_correct
123125
resources_correct = resources_correct and datastore_correct
124126
out['datastore_rows'] = ds.get('total', 0)
125127
out['datastore_active'] = True
@@ -437,6 +439,17 @@ def _datastore_match(fs: List[Dict[str, Any]], fields: List[Dict[str, Any]]) ->
437439
if not f.get('published_resource_computed_field', False))
438440

439441

442+
def _schema_match(fs: List[Dict[str, Any]], fields: List[Dict[str, Any]]) -> bool:
443+
"""
444+
return True if datastore column fields are all fields defined in fs.
445+
"""
446+
# XXX: does not check types or extra columns at this time
447+
existing = set(f['datastore_id'] for f in fs
448+
if not f.get('published_resource_computed_field', False))
449+
return all(c['id'] in existing for c in fields
450+
if c['id'] != '_id')
451+
452+
440453
@chained_action
441454
@side_effect_free
442455
def recombinant_datastore_info(up_func: Action,

ckanext/recombinant/templates/recombinant/resource_edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{% block action_panels %}
4646
{% if dataset %}
4747
{% if 'error' not in resource %}
48-
{% if g.userobj.sysadmin and not resource.datastore_correct %}
48+
{% if g.userobj.sysadmin and (not resource.datastore_correct or not resource.schema_correct) %}
4949
{# only let sysadmins refresh the recombinant record via UI #}
5050
<div class="module-alert alert alert-warning">
5151
<h3>{{ _("The Recombinant resource is out of date") }}{% snippet 'snippets/sysadmin_only.html' %}</h3>

ckanext/recombinant/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ def preview_table(resource_name: str,
611611
# check that the resource has errors
612612
for _r in dataset['resources']:
613613
if _r['name'] == resource_name and ('error' in _r or
614-
not _r['datastore_correct']):
614+
not _r['datastore_correct'] or
615+
not _r['schema_correct']):
615616
raise NotFound
616617
except NotFound:
617618
try:

0 commit comments

Comments
 (0)