Skip to content

Commit 7fdcc3f

Browse files
Raise validation errors for missing schema and permissions
1 parent 43adabf commit 7fdcc3f

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

cumulusci/tasks/bulkdata/mapping_parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ def replace_if_necessary(dct, name, replacement):
444444
except KeyError:
445445
message = f"Field {self.sf_object}.{f} does not exist or is not visible to the current user."
446446
if validation_result:
447-
validation_result.add_warning(message)
447+
validation_result.add_error(message)
448448
else:
449-
logger.warning(message)
449+
logger.error(message)
450450
else:
451451
del field_dict[f]
452452
field_dict[new_name] = entry
@@ -463,9 +463,9 @@ def replace_if_necessary(dct, name, replacement):
463463
if f not in describe:
464464
message = f"Field {self.sf_object}.{f} does not exist or is not visible to the current user."
465465
if validation_result:
466-
validation_result.add_warning(message)
466+
validation_result.add_error(message)
467467
else:
468-
logger.warning(message)
468+
logger.error(message)
469469
error_in_f = True
470470
elif not self._check_field_permission(
471471
describe,
@@ -480,9 +480,9 @@ def replace_if_necessary(dct, name, replacement):
480480
+ f"{relevant_permissions} for this operation."
481481
)
482482
if validation_result:
483-
validation_result.add_warning(message)
483+
validation_result.add_error(message)
484484
else:
485-
logger.warning(message)
485+
logger.error(message)
486486
error_in_f = True
487487

488488
if error_in_f:
@@ -514,9 +514,9 @@ def _validate_sobject(
514514
except KeyError:
515515
message = f"sObject {self.sf_object} does not exist or is not visible to the current user."
516516
if validation_result:
517-
validation_result.add_warning(message)
517+
validation_result.add_error(message)
518518
else:
519-
logger.warning(message)
519+
logger.error(message)
520520
return False
521521

522522
# Validate our access to this sObject.
@@ -525,9 +525,9 @@ def _validate_sobject(
525525
):
526526
message = f"sObject {self.sf_object} does not have the correct permissions for {data_operation_type}."
527527
if validation_result:
528-
validation_result.add_warning(message)
528+
validation_result.add_error(message)
529529
else:
530-
logger.warning(message)
530+
logger.error(message)
531531
return False
532532

533533
return True

cumulusci/tasks/bulkdata/tests/test_mapping_parser.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,9 @@ def test_validate_only_collects_missing_field_errors(self):
18681868

18691869
assert result is not None
18701870
assert isinstance(result, ValidationResult)
1871-
# Should have warnings about missing field
1872-
assert any("Nonsense__c" in warning for warning in result.warnings)
1871+
assert result.has_errors()
1872+
# Should have errors about missing field
1873+
assert any("Nonsense__c" in error for error in result.errors)
18731874

18741875
@responses.activate
18751876
def test_validate_only_collects_missing_required_field_errors(self):
@@ -1930,8 +1931,9 @@ def test_validate_only_early_return_on_sobject_error(self):
19301931

19311932
assert result is not None
19321933
assert isinstance(result, ValidationResult)
1933-
# Should have warning about missing object
1934-
assert any("InvalidObject__c" in warning for warning in result.warnings)
1934+
assert result.has_errors()
1935+
# Should have error about missing object
1936+
assert any("InvalidObject__c" in error for error in result.errors)
19351937

19361938
@responses.activate
19371939
def test_validate_only_collects_lookup_errors(self):
@@ -2068,7 +2070,7 @@ def test_check_required_without_validation_result_logs(self, caplog):
20682070
assert "Name" in caplog.text
20692071

20702072
def test_validate_sobject_with_validation_result(self):
2071-
"""Test _validate_sobject adds warnings to ValidationResult"""
2073+
"""Test _validate_sobject adds errors to ValidationResult"""
20722074
from cumulusci.tasks.bulkdata.mapping_parser import ValidationResult
20732075

20742076
ms = MappingStep(
@@ -2087,13 +2089,11 @@ def test_validate_sobject_with_validation_result(self):
20872089
)
20882090

20892091
assert not result
2090-
assert len(validation_result.warnings) > 0
2091-
assert any(
2092-
"InvalidObject__c" in warning for warning in validation_result.warnings
2093-
)
2092+
assert validation_result.has_errors()
2093+
assert any("InvalidObject__c" in error for error in validation_result.errors)
20942094

20952095
def test_validate_field_dict_with_validation_result(self):
2096-
"""Test _validate_field_dict adds warnings to ValidationResult"""
2096+
"""Test _validate_field_dict adds errors to ValidationResult"""
20972097
from cumulusci.tasks.bulkdata.mapping_parser import ValidationResult
20982098

20992099
ms = MappingStep(
@@ -2114,10 +2114,8 @@ def test_validate_field_dict_with_validation_result(self):
21142114
)
21152115

21162116
assert not result
2117-
assert len(validation_result.warnings) > 0
2118-
assert any(
2119-
"NonexistentField__c" in warning for warning in validation_result.warnings
2120-
)
2117+
assert validation_result.has_errors()
2118+
assert any("NonexistentField__c" in error for error in validation_result.errors)
21212119

21222120
def test_infer_and_validate_lookups_with_validation_result(self):
21232121
"""Test _infer_and_validate_lookups adds errors to ValidationResult"""
@@ -2235,10 +2233,11 @@ def test_validate_field_dict_permission_error_with_validation_result(self):
22352233
)
22362234

22372235
assert not result
2238-
# Should have warning about incorrect permissions
2236+
assert validation_result.has_errors()
2237+
# Should have error about incorrect permissions
22392238
assert any(
2240-
"does not have the correct permissions" in warning
2241-
for warning in validation_result.warnings
2239+
"does not have the correct permissions" in error
2240+
for error in validation_result.errors
22422241
)
22432242

22442243
def test_validate_sobject_permission_error_with_validation_result(self):
@@ -2261,10 +2260,11 @@ def test_validate_sobject_permission_error_with_validation_result(self):
22612260
)
22622261

22632262
assert not result
2264-
# Should have warning about incorrect permissions
2263+
assert validation_result.has_errors()
2264+
# Should have error about incorrect permissions
22652265
assert any(
2266-
"does not have the correct permissions" in warning
2267-
for warning in validation_result.warnings
2266+
"does not have the correct permissions" in error
2267+
for error in validation_result.errors
22682268
)
22692269

22702270
def test_infer_and_validate_lookups_invalid_reference_with_validation_result(self):

0 commit comments

Comments
 (0)