Skip to content

Commit f953048

Browse files
author
Jackson Maxfield Brown
authored
bugfix/revert-validator-fixes (#164)
* Revert "cleanup/remove-is-required-from-constant-validator (#163)" This reverts commit c5c3395. * Make allow none / optional behavior more explicit * Use allow none in tests and models * Lint * Simplify even further
1 parent 290d573 commit f953048

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cdp_backend/database/validators.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def create_constant_value_validator(constant_cls: Type) -> Callable[[str], bool]
169169
-------
170170
validator_func: Callable[[str], bool]
171171
The validator func.
172+
173+
Notes
174+
-----
175+
Will always allow `None` as a valid option.
176+
To remove `None` as a viable input, set the database model field `required=True`.
177+
178+
See: https://github.com/CouncilDataProject/cdp-backend/pull/164
172179
"""
173180

174181
def is_valid(value: str) -> bool:
@@ -185,6 +192,6 @@ def is_valid(value: str) -> bool:
185192
status: bool
186193
The validation status.
187194
"""
188-
return value in get_all_class_attr_values(constant_cls)
195+
return value is None or value in get_all_class_attr_values(constant_cls)
189196

190197
return is_valid

cdp_backend/pipeline/event_gather_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ def store_event_processing_results(
14211421
db_model=matter_status_db_model,
14221422
credentials_file=credentials_file,
14231423
)
1424-
except FieldValidationFailed:
1424+
except (FieldValidationFailed, RequiredField):
14251425
allowed_matter_decisions = (
14261426
constants_utils.get_all_class_attr_values(
14271427
db_constants.MatterStatusDecision

cdp_backend/tests/database/test_validators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_remote_resource_exists(
136136
@pytest.mark.parametrize(
137137
"decision, expected_result",
138138
[
139+
(None, True), # None always allowed in validator, rejected by model
139140
("Approve", True),
140141
("INVALID", False),
141142
],
@@ -149,6 +150,7 @@ def test_vote_decision_is_valid(decision: str, expected_result: bool) -> None:
149150
@pytest.mark.parametrize(
150151
"decision, expected_result",
151152
[
153+
(None, True), # None always allowed in validator, allowed by model
152154
("Passed", True),
153155
("INVALID", False),
154156
],
@@ -157,7 +159,7 @@ def test_event_minutes_item_decision_is_valid(
157159
decision: str, expected_result: bool
158160
) -> None:
159161
validator_func = validators.create_constant_value_validator(
160-
EventMinutesItemDecision
162+
EventMinutesItemDecision,
161163
)
162164
actual_result = validator_func(decision)
163165
assert actual_result == expected_result
@@ -166,19 +168,23 @@ def test_event_minutes_item_decision_is_valid(
166168
@pytest.mark.parametrize(
167169
"decision, expected_result",
168170
[
171+
(None, True), # None always allowed in validator, rejected by model
169172
("Adopted", True),
170173
("INVALID", False),
171174
],
172175
)
173176
def test_matter_status_decision_is_valid(decision: str, expected_result: bool) -> None:
174-
validator_func = validators.create_constant_value_validator(MatterStatusDecision)
177+
validator_func = validators.create_constant_value_validator(
178+
MatterStatusDecision,
179+
)
175180
actual_result = validator_func(decision)
176181
assert actual_result == expected_result
177182

178183

179184
@pytest.mark.parametrize(
180185
"title, expected_result",
181186
[
187+
(None, True), # None always allowed in validator, rejected by model
182188
("Councilmember", True),
183189
("INVALID", False),
184190
],

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@
130130
"run_cdp_event_index=cdp_backend.bin.run_cdp_event_index:main",
131131
"search_cdp_events=cdp_backend.bin.search_cdp_events:main",
132132
"process_special_event=cdp_backend.bin.process_special_event:main",
133-
"add_content_hash_to_sessions=cdp_backend.bin.add_content_hash_to_sessions:main",
133+
(
134+
"add_content_hash_to_sessions="
135+
"cdp_backend.bin.add_content_hash_to_sessions:main"
136+
),
134137
],
135138
},
136139
install_requires=requirements,

0 commit comments

Comments
 (0)