raft-tech / TANF-app

Repo for development of a new TANF Data Reporting System
Other
16 stars 3 forks source link

Spike - Cat2 Validator Improvement #3016

Open jtimpe opened 1 month ago

jtimpe commented 1 month ago

Description:

2963 makes updates to cat2 validators to include information about the record/field (schema, item number, and friendly name) within the error message. This has a little side effect when the same cat2 validator functions are used within cat3 if/then validators - the item numbers are wrong and the error message contains the extra information for each field and becomes overwhelming/hard to read

Investigate cleaning up the cat3 error messages. Some possible approaches:

Support References

Open Questions: Please include any questions, possible solutions or decisions that should be explored during work

Deliverable(s): Create a list of recommendations or proofs of concept to be achieved to complete this issue

jtimpe commented 3 weeks ago

In order to appropriately format all the error messages regardless of how they're used (cat2 or cat3), i'm going to implement different options for the format_error_context function, i.e.

def format_error_context(row_schema, friendly_name, item_num, format='prefix'):
    """Format the error message for consistency across cat2 validators."""
    match format:
        case 'inline':
            return f'Item {item_num} ({friendly_name})'

        case 'prefix' | _:
            return f'{row_schema.record_type} Item {item_num} ({friendly_name}):'

this will require a lot of changes (the context needs to be passed along to all of the validators and used in the format_error_context call) but should allow us to continue to use the same validator functions, and make all of the cat2 validator functions available to the cat3 if_then_validator.

getting the field information from the row schema within if_then_validator turned out to be simple:

field = row_schema.get_field_by_name(condition_field_name)

which allows the field.friendly_name and field.item to be passed to the cat2 validator functions (along with the new 'inline' option)

validator1_result = condition_function(value1, row_schema, condition_field.friendly_name, condition_field.item, 'inline')

Together, these changes should set up #2792 to be completed relatively easily. So far I have both implemented, but have roughly 2 points remaining to finish out the tests.

robgendron commented 3 weeks ago

3 points remaining.

robgendron commented 2 weeks ago

2 points remaining, PR coming soon.

robgendron commented 1 week ago

Pending 1 more Raft review.