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

feat(workflow-engine): add EventAttributeConditionHandler #82741

Merged
merged 4 commits into from
Jan 2, 2025

Conversation

ameliahsu
Copy link
Member

add EventAttributeConditionHandler

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 30, 2024
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool:
event = job["event"]

attribute = comparison.get("attribute", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think comparison is stored as a string so you'll need to do json.loads(comparison) to get it as a dictionary

) -> DataCondition:
return DataCondition.objects.create(
type=Condition.EVENT_ATTRIBUTE,
comparison=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are the attribute, match type, and desired value being stored? one way to do this is to put them in a dictionary and json.dump them into comparison here

@condition_handler_registry.register(Condition.EVENT_ATTRIBUTE)
class EventAttributeConditionHandler(DataConditionHandler[WorkflowJob]):
@staticmethod
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if there's a lot happening in this function you can also break it up into several smaller ones

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 98.29545% with 6 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
..._engine/handlers/condition/group_event_handlers.py 85.36% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #82741      +/-   ##
==========================================
+ Coverage   87.49%   87.64%   +0.15%     
==========================================
  Files        9408     9409       +1     
  Lines      538586   545517    +6931     
  Branches    21036    21036              
==========================================
+ Hits       471245   478137    +6892     
- Misses      66970    67009      +39     
  Partials      371      371              

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far

Comment on lines 204 to 210
dc = self.create_data_condition(
type=self.condition,
comparison=json.dumps(
{"match": MatchType.NOT_STARTS_WITH, "attribute": "platform", "value": "py"}
),
condition_result=True,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to avoid creating another data condition, you can also update the comparison field from the previously created data condition

return False

desired_value = str(desired_value).lower()
attribute_values = [str(value).lower() for value in attribute_values if value is not None]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this go inside get_attribute_values?

Comment on lines 214 to 218
comparison = {
"match": MatchType.EQUAL,
"value": "php",
"attribute": "platform",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make self.payload on line 54 this without updating it here, you're not using it anywhere else rn

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cat Apple

)
self.assert_does_not_pass(self.dc, self.job)

def test_equals(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be more readable if you split the tests into one class to test the comparisons (equals, contains, etc) and one to test the attributes?

self.assert_does_not_pass(self.dc, self.job)

def test_equals(self):
self.dc.comparison = json.dumps(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you wanted to change the value in the DB you should do self.dc.update(comparison=...) or self.dc.comparison = ... and self.dc.save()

i think it doesn't affect it here because the model class maintains state and we aren't querying for the data condition somewhere else

@ameliahsu ameliahsu merged commit 30d47e5 into master Jan 2, 2025
49 checks passed
ameliahsu added a commit that referenced this pull request Jan 2, 2025
@ameliahsu ameliahsu deleted the mia/aci/event_attribute branch January 2, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants