[Bug] Fix annotations update/patch (#60385)

* fix annotations update/patch

* verify that when update doesn't contain data, we will not update data
This commit is contained in:
ying-jeanne
2022-12-26 09:53:52 -05:00
committed by GitHub
parent 746c7839dc
commit 12c292fd44
4 changed files with 63 additions and 11 deletions
+10
View File
@@ -278,6 +278,11 @@ func (hs *HTTPServer) UpdateAnnotation(c *models.ReqContext) response.Response {
EpochEnd: cmd.TimeEnd,
Text: cmd.Text,
Tags: cmd.Tags,
Data: annotation.Data,
}
if cmd.Data != nil {
item.Data = cmd.Data
}
if err := hs.annotationsRepo.Update(c.Req.Context(), &item); err != nil {
@@ -328,6 +333,7 @@ func (hs *HTTPServer) PatchAnnotation(c *models.ReqContext) response.Response {
EpochEnd: annotation.TimeEnd,
Text: annotation.Text,
Tags: annotation.Tags,
Data: annotation.Data,
}
if cmd.Tags != nil {
@@ -346,6 +352,10 @@ func (hs *HTTPServer) PatchAnnotation(c *models.ReqContext) response.Response {
existing.EpochEnd = cmd.TimeEnd
}
if cmd.Data != nil {
existing.Data = cmd.Data
}
if err := hs.annotationsRepo.Update(c.Req.Context(), &existing); err != nil {
return response.ErrOrFallback(500, "Failed to update annotation", err)
}