Repository navigation
Allow fact updates to fields whose current value is falsy - #3426
Open
bacescuandrei wants to merge 1 commit into
Open
bacescuandrei wants to merge 1 commit into
bacescuandrei wants to merge 1 commit into
Conversation
_update_fact() only applied an update when the current attribute value was truthy, so a fact with score 0, technique_id None or an empty source could not be updated through the knowledge service or PATCH /api/v2/facts. A fact whose score dropped to 0 is excluded from Operation.all_facts() and could not be given a positive score again. Check that the attribute exists instead, as _update_relationship() already does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BaseKnowledgeService._update_fact()only applies an update when the current attribute value is truthy:So
knowledge_svc.update_fact()andPATCH /api/v2/factssilently ignore updates to fields whose current value is0,None,''or[]. Examples are a fact withscore0,technique_idNone, or an emptysource.Operation.all_facts()only returns facts withscore > 0, so a fact whose score dropped to 0 can never be given a positive score again.This change checks that the attribute exists (
hasattr), as_update_relationship()already does.Type of change
How Has This Been Tested?
test_update_fact_with_falsy_current_valuetotests/services/test_knowledge_svc.py. It updatesscorefrom 0 andtechnique_idfrom None, and checks that an unknown key is not added.assert 0 == 2) and passes with the change.Checklist: