Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing type/compliance requirement validation error #4603

Merged
merged 8 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/audit/intakelib/mapping_audit_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def extract_audit_findings(file, is_gsa_migration=False, auditee_uei=None):
def audit_findings_named_ranges(errors):
return _extract_named_ranges(
errors,
audit_findings_field_mapping,
audit_findings_column_mapping,
audit_findings_field_mapping,
meta_mapping,
)

Expand Down
48 changes: 26 additions & 22 deletions backend/audit/intakelib/mapping_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,26 @@ def _open_workbook(file):
def _get_entries_by_path(dictionary, path):
keys = path.split(".")
val = dictionary

for key in keys:
try:
val = val[key]
except KeyError:
return []

return val


def _extract_from_column_mapping(path, row_index, column_mapping, match=None):
def _extract_from_column_mapping(path, column_mapping, match=None):
"""Extract named ranges from column mapping"""
for key, value in column_mapping.items():
if len(value) > 2 and (
value[0] + "." + value[1] == path
or (match and value[0] + "." + value[1] == path + "." + match.group(1))
):
return key, row_index
return None, None
return key

return None


def _extract_from_field_mapping(path, field_mapping, match=None):
Expand All @@ -95,58 +98,59 @@ def _extract_from_field_mapping(path, field_mapping, match=None):
if len(value) == 2 and (
value[0] == path or (match and value[0] == ".".join([path, match.group(1)]))
):
return key, None
return None, None
return key

return None


def _extract_error_details(error):
if not bool(error.path):
logger.info("No path found in error object")
return None, None, None

row_index = next((item for item in error.path if isinstance(item, int)), None)
path = ".".join([item for item in error.path if not isinstance(item, int)])
match = re.search(r"'(\w+)'", error.message) if error.message else None

return path, row_index, match


def _extract_key_from_award_entities(path, row_index, named_ranges):
def _extract_key_from_award_entities(path, named_ranges):
if path in [AWARD_ENTITY_NAME_PATH, AWARD_ENTITY_ID_PATH]:
key = (
AWARD_ENTITY_NAME_KEY
if path == AWARD_ENTITY_NAME_PATH
else AWARD_ENTITY_ID_KEY
)
named_ranges.append((key, row_index))

return key

return None


def _extract_named_ranges(errors, column_mapping, field_mapping, meta_mapping):
"""Extract named ranges from column mapping and errors"""
named_ranges = []

for error in errors:
path, row_index, match = _extract_error_details(error)
if not path:
continue

# Extract named ranges from column mapping for award entities
keyFound = _extract_key_from_award_entities(path, row_index, named_ranges)
key_found = _extract_key_from_award_entities(path, named_ranges)

if not key_found:
key_found = _extract_from_column_mapping(path, column_mapping, match)

if not keyFound:
keyFound, row_index = _extract_from_column_mapping(
path, row_index, column_mapping, match
)
if keyFound:
named_ranges.append((keyFound, row_index))
if not key_found:
key_found = _extract_from_field_mapping(path, field_mapping, match)

if not keyFound:
keyFound, _ = _extract_from_field_mapping(path, field_mapping, match)
if not keyFound:
keyFound, _ = _extract_from_field_mapping(path, meta_mapping, match)
if keyFound:
named_ranges.append((keyFound, None))
if not key_found:
key_found = _extract_from_field_mapping(path, meta_mapping, match)

if not keyFound:
if key_found:
named_ranges.append((key_found, row_index))
else:
logger.info(f"No named range matches this error path: {error.path}")

return named_ranges
Loading