Can't resolve ID of not-yet-adopted item
zdrve opened this issue · comments
Rachel Evans commented
Example:
- we have an SLO, which exists in datadog, but not in kennel
- we prepare a PR to import that SLO into kennel
rake kennel:update_datadog PROJECT=my_project
works, but doesn't add the tracking_id
This is all fine so far. But now comes the problem:
- on the same PR, we add a widget to some dashboard, with
slo_id: "my_project:my_new_slo"
rake kennel:update_datadog PROJECT=my_project
fails, saying it can't resolvemy_project:my_new_slo
.
Very hacky fix:
diff --git a/lib/kennel/syncer.rb b/lib/kennel/syncer.rb
index fec037e..82eb87c 100644
--- a/lib/kennel/syncer.rb
+++ b/lib/kennel/syncer.rb
@@ -105,7 +105,15 @@ module Kennel
# Refuse to "adopt" existing items into kennel while running with a filter (i.e. on a branch).
# Without this, we'd adopt an item, then the next CI run would delete it
# (instead of "unadopting" it).
- e.add_tracking_id unless filter.filtering? && a.fetch(:tracking_id).nil?
+ if filter.filtering? && a.fetch(:tracking_id).nil?
+ # Eww!
+ a[:tracking_id] = e.tracking_id
+ resolver.add_actual([a])
+ a[:tracking_id] = nil
+ else
+ e.add_tracking_id
+ end
+
id = a.fetch(:id)
diff = e.diff(a)
a[:id] = id
Michael Grosser commented
yeah good solution for an ugly edge-case :)