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

DEVPROD-4661: Correctly update has_annotations field in task annotation REST routes #8545

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

minnakt
Copy link
Contributor

@minnakt minnakt commented Dec 10, 2024

DEVPROD-4661

Description

This task is returning Known Issue because the value of the cached field has_annotations is true, even though the task_annotations collection has no issues recorded for this task and execution. This is a bug where the task.has_annotations field is out of sync with the task_annotations collection.

I could not replicate this bug through the GraphQL resolvers. When I added, moved, and removed issues from the UI, the has_annotations field was always correctly in sync.

The only time I could replicate this bug was by using the task annotations PUT rest route to clear the task annotations. The PUT route does not call UnsetHasAnnotations, which can lead to the has_annotations field being out of sync.

Testing

  • Added test that fails without the changes in this PR
  • Tested on staging

@@ -36,7 +36,7 @@ func MoveIssueToSuspectedIssue(taskId string, taskExecution int, issue annotatio
if err != nil {
return errors.Wrapf(err, "finding and modifying task annotation for execution %d of task '%s'", taskExecution, taskId)
}
if annotation != nil && len(annotation.Issues) == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was giving me a lint error that annotation cannot be nil by nature of how it's defined, so it's redundant

@minnakt minnakt marked this pull request as ready for review December 10, 2024 18:29
@minnakt minnakt requested a review from a team December 10, 2024 18:29
@@ -152,8 +152,12 @@ func UpsertAnnotation(a *annotations.TaskAnnotation, userDisplayName string) err
); err != nil {
return errors.Wrapf(err, "adding task annotation for task '%s'", a.TaskId)
}
if a.Issues != nil && len(a.Issues) > 0 {
return SetHasAnnotations(a.TaskId, a.TaskExecution)
if a.Issues != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly, you don't need to check nil here -- length of the list will just return 0 if its nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ended up having to keep the nil check because it broke the existing tests (that someone previously added)

return SetHasAnnotations(a.TaskId, a.TaskExecution)
if a.Issues != nil {
if len(a.Issues) == 0 {
return UnsetHasAnnotations(a.TaskId, a.TaskExecution)
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is too big of a refactor for this PR we can split a ticket, but i feel like we should just have one function, that sets annotations to true or false based on the length of issues (or at least that takes in a boolean, so we could just pass through len(a.Issues)==0 as the bool), rather than having this if statement

hasAnnotations := len(a.Issues) > 0
return UpdateHasAnnotations(a.TaskId, a.TaskExecution, hasAnnotations)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you got it boss ‼️

@minnakt minnakt changed the title DEVPROD-4661: Call UnsetHasAnnotations in task annotation REST routes DEVPROD-4661: Correctly update has_annotations field in task annotation REST routes Dec 10, 2024
@minnakt minnakt requested a review from ablack12 December 11, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants