-
Notifications
You must be signed in to change notification settings - Fork 25
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
feature/remove-is-required-from-constant-validator #163
feature/remove-is-required-from-constant-validator #163
Conversation
Codecov Report
@@ Coverage Diff @@
## main #163 +/- ##
==========================================
- Coverage 94.57% 94.56% -0.01%
==========================================
Files 50 50
Lines 2560 2558 -2
==========================================
- Hits 2421 2419 -2
Misses 139 139
Continue to review full report at Codecov.
|
@@ -136,21 +136,19 @@ def test_remote_resource_exists( | |||
@pytest.mark.parametrize( | |||
"decision, expected_result", | |||
[ | |||
(None, False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making me question what the pattern is. Before I approve can you show me code that has a random FireO model with a field thats required fail to push with a None
value?
Like I want to make sure that regardless of this change, that None
values for required fields are still rejected from upload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, here's an example code snippet I ran:
matter_status = MatterStatus()
matter_status.matter_ref = Matter.Example()
matter_status.status = None
upload_db_model(matter_status, config.google_credentials_file)
It will raise a FireO RequiredField
exception:
Traceback (most recent call last):
File "/Users/Isaac/Desktop/CDP/cdp-backend/cdp_backend/database/functions.py", line 107, in upload_db_model
db_model = db_model.upsert(transaction=transaction, batch=batch)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/models/model.py", line 352, in upsert
return self.save(transaction=transaction, batch=batch, merge=True)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/models/model.py", line 346, in save
return self.__class__.collection.create(self, transaction, batch, merge, no_return, **self._get_fields())
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/managers/managers.py", line 230, in create
return self.queryset.create(mutable_instance, transaction, batch, merge, no_return, **field_list)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/queries/query_set.py", line 56, in create
return CreateQuery(self.model_cls, mutable_instance, no_return, **kwargs).exec(transaction_or_batch, merge)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/queries/create_query.py", line 158, in exec
return query_wrapper.ModelWrapper.from_query_result(self.model, self._raw_exec(merge=merge))
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/queries/create_query.py", line 143, in _raw_exec
ref.set(self._parse_field(), merge=merge)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/queries/create_query.py", line 97, in _parse_field
fv = f.get_value(self.query.get(f.name))
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/fields/base_field.py", line 122, in get_value
val = self.field_attribute.parse(val, ignore_required, ignore_default)
File "/Users/Isaac/.local/share/virtualenvs/cdp-backend-9V6eR1KV/lib/python3.7/site-packages/fireo/fields/field_attribute.py", line 86, in parse
raise RequiredField(f'"{self.field.__class__.__name__}" is required for model {self.field.model_cls} '
fireo.fields.errors.RequiredField: "TextField" is required for model <class 'cdp_backend.database.models.MatterStatus'> but received no default and no value.
Same thing happens when we don't set status
at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If upload fails due to a required field not being present, do we want to fail on the pipeline or keep proceeding? If it's the latter, then I can update the PR to catch RequiredField
for uploads.
I'm thinking it's one thing to proceed if validation fails, but if something like a required field is gone, it could be worth stopping the pipeline because that could mean something is wrong with the data source of the ingestion models
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I think it depends on the case. I wonder if this was why we split them up initially? I will go through this PR and see which ones are needed and which one are truly optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly. The more I look at this the more I am concerned I am missing something. Like was there a reason we originally included this param??
Looking at the pipeline code: https://github.com/CouncilDataProject/cdp-backend/blob/main/cdp_backend/pipeline/event_gather_pipeline.py#L1133
If we were to merge this PR, that line wouldn't break it would just raise a different error correct?
BUT, looking at this: https://github.com/CouncilDataProject/cdp-backend/blob/main/cdp_backend/pipeline/event_gather_pipeline.py#L1413
I think this would break some stuff because passing None
would now be allowed through the validator I think but would raise a requiredField error that isn't current caught?
I don't think To had a specific reason, but may have just added it if he didn't know about the
Yeah this wouldn't break, it'd just throw
So I tested this out, and technically there would be no change to the existing functionality. If you look at this PR. We used the FireO So we're already (and always have been) throwing Btw, the |
So TLDR: the validator param |
Oh. Well that alone has convinced me. Sounds good. Thanks for the additional comments and research. |
This reverts commit c5c3395.
Link to Relevant Issue
This pull request resolves #160
Description of Changes
Removing
is_required
and since we can use FireO'sRequired=True
wherever applicable.