Skip to content

Commit

Permalink
3113 added validation skip error
Browse files Browse the repository at this point in the history
  • Loading branch information
raftmsohani committed Aug 6, 2024
1 parent cfe6e8a commit 6b8c434
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
7 changes: 5 additions & 2 deletions tdrs-backend/tdpservice/parsers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
endIndex,
required=True,
validators=[],
ignore_errors=False,
):
self.item = item
self.name = name
Expand All @@ -27,6 +28,7 @@ def __init__(
self.endIndex = endIndex
self.required = required
self.validators = validators
self.ignore_errors = ignore_errors

def create(self, item, name, length, start, end, type):
"""Create a new field."""
Expand Down Expand Up @@ -64,7 +66,7 @@ class TransformField(Field):
"""Represents a field that requires some transformation before serializing."""

def __init__(self, transform_func, item, name, friendly_name, type, startIndex, endIndex, required=True,
validators=[], **kwargs):
validators=[], ignore_errors=False, **kwargs):
super().__init__(
item=item,
name=name,
Expand All @@ -73,7 +75,8 @@ def __init__(self, transform_func, item, name, friendly_name, type, startIndex,
startIndex=startIndex,
endIndex=endIndex,
required=required,
validators=validators)
validators=validators,
ignore_errors=ignore_errors)
self.transform_func = transform_func
self.kwargs = kwargs

Expand Down
4 changes: 4 additions & 0 deletions tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def parse_datafile(datafile, dfs):
errors['header'] = header_errors
bulk_create_errors({1: header_errors}, 1, flush=True)
return errors
elif header_is_valid and len(header_errors) > 0:
logger.info(f"Preparser Warning: {len(header_errors)} header warnings encountered.")
errors['header'] = header_errors
bulk_create_errors({1: header_errors}, 1, flush=True)

field_values = schema_defs.header.get_field_values_by_names(header_line,
{"encryption", "tribe_code", "state_fips"})
Expand Down
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def run_field_validators(self, instance, generate_error):
if (field.required and not is_empty) or should_validate:
for validator in field.validators:
validator_is_valid, validator_error = validator(value, self, field.friendly_name, field.item)
is_valid = False if not validator_is_valid else is_valid
is_valid = False if (not validator_is_valid and not field.ignore_errors) else is_valid
if validator_error:
errors.append(
generate_error(
Expand Down
16 changes: 11 additions & 5 deletions tdrs-backend/tdpservice/parsers/schema_defs/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@
startIndex=22,
endIndex=23,
required=True,
validators=[validators.matches("D",
error_func=lambda eargs: ("HEADER Update Indicator must be set to D "
f"instead of {eargs.value}. Please review "
"Exporting Complete Data Using FTANF in the "
"Knowledge Center."))],
validators=[
validators.matches(
"D",
error_func=lambda eargs: (
"HEADER Update Indicator must be set to D "
f"instead of {eargs.value}. Please review "
"Exporting Complete Data Using FTANF in the "
"Knowledge Center."
),
)],
ignore_errors=True,
),
],
)
4 changes: 2 additions & 2 deletions tdrs-backend/tdpservice/parsers/test/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_header_cleanup(test_datafile):
# Encryption error
("HEADER20204A06 TAN1AD", False, "HEADER Item 9 (encryption): A is not in [ , E]."),
# Update error
("HEADER20204A06 TAN1EA", False, ("HEADER Update Indicator must be set to D instead of A. Please review "
"Exporting Complete Data Using FTANF in the Knowledge Center.")),
("HEADER20204A06 TAN1EA", True, ("HEADER Update Indicator must be set to D instead of A. Please review "
"Exporting Complete Data Using FTANF in the Knowledge Center.")),
])
@pytest.mark.django_db
def test_header_fields(test_datafile, header_line, is_valid, error):
Expand Down
12 changes: 4 additions & 8 deletions tdrs-backend/tdpservice/parsers/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,16 +1610,12 @@ def test_parse_tanf_section_1_file_with_bad_update_indicator(tanf_section_1_file

parser_errors = ParserError.objects.filter(file=tanf_section_1_file_with_bad_update_indicator)

assert parser_errors.count() == 1

error = parser_errors.first()
assert parser_errors.count() == 5

assert error.error_type == ParserErrorCategoryChoices.FIELD_VALUE
assert error.error_message == ("HEADER Update Indicator must be set to D "
"instead of U. Please review "
"Exporting Complete Data Using FTANF in the "
"Knowledge Center.")
error_messages = [error.error_message for error in parser_errors]

assert "HEADER Update Indicator must be set to D instead of U. Please review" + \
" Exporting Complete Data Using FTANF in the Knowledge Center." in error_messages

@pytest.mark.django_db()
def test_parse_tribal_section_4_bad_quarter(tribal_section_4_bad_quarter, dfs):
Expand Down

0 comments on commit 6b8c434

Please sign in to comment.