From 2cd7cbd56f08117384b92c5628207b13422b937f Mon Sep 17 00:00:00 2001 From: Pierre Dittgen Date: Tue, 23 Jul 2019 09:11:37 +0200 Subject: [PATCH] Always display body errors --- validata_ui/views.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/validata_ui/views.py b/validata_ui/views.py index a4337cb..7fa9042 100644 --- a/validata_ui/views.py +++ b/validata_ui/views.py @@ -22,7 +22,7 @@ from flask import abort, make_response, redirect, render_template, request, url_ import tabulator from opendataschema import GitSchemaReference, by_commit_date -from validata_core import messages +from validata_core import messages, repair from . import app, config, schema_catalog_registry, tableschema_from_url from .ui_util import flash_error, flash_warning @@ -132,7 +132,7 @@ class SchemaInstance: return None -def extract_source_data(source: ValidataResource, preview_rows_nb=5): +def extract_source_data(source: ValidataResource, schema_descriptor, preview_rows_nb=5): """ Computes table preview """ def stringify(val): @@ -144,7 +144,8 @@ def extract_source_data(source: ValidataResource, preview_rows_nb=5): nb_rows = 0 tabulator_source, tabulator_options = source.build_tabulator_stream_args() - with tabulator.Stream(tabulator_source, **tabulator_options) as stream: + fixed_source, _ = repair(tabulator_source, schema_descriptor, **tabulator_options) + with tabulator.Stream(fixed_source, {**tabulator_options, 'scheme': 'stream', 'format': 'inline'}) as stream: for row in stream: if header is None: header = ['' if v is None else v for v in row] @@ -243,10 +244,10 @@ def create_validata_ui_report(validata_core_report, schema_dict): else: report['table']['errors']['body'].append(err) - # Checks if there are structure errors different to invalid-column-delimiter structure_errors = report['table']['errors']['structure'] - report['table']['do_display_body_errors'] = len(structure_errors) == 0 or \ - all(err['code'] == 'invalid-column-delimiter' for err in structure_errors) + + # Always displays body errors + report['table']['do_display_body_errors'] = True # Checks if a column comparison is needed header_errors = ('missing-headers', 'extra-headers', 'wrong-headers-order') @@ -381,7 +382,7 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource): flash_error('Erreur de source : {}'.format(msg)) return redirect(url_for('custom_validator')) - source_data = extract_source_data(source) + source_data = extract_source_data(source, schema_instance.schema.descriptor) # handle report date report_datetime = datetime.fromisoformat(validata_core_report['date']).astimezone() -- GitLab