Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(sync): scope after_commit to prevent nil family error on destroy (#1976)

sentry[bot]174a2e19f928
diff --git a/app/models/sync.rb b/app/models/sync.rb
index 83cb439ce0..0bc2d6d013 100644
--- a/app/models/sync.rb
+++ b/app/models/sync.rb
@@ -19,7 +19,7 @@ class Sync < ApplicationRecord
scope :incomplete, -> { where("syncs.status IN (?)", %w[pending syncing]) }
scope :visible, -> { incomplete.where("syncs.created_at > ?", VISIBLE_FOR.ago) }
- after_commit :update_family_sync_timestamp
+ after_commit :update_family_sync_timestamp, on: [ :create, :update ]
serialize :sync_stats, coder: JSON
@@ -258,12 +258,14 @@ class Sync < ApplicationRecord
end
def update_family_sync_timestamp
- return unless family.persisted?
+ return unless family&.persisted?
family.touch(:latest_sync_activity_at)
end
def family
+ return nil unless syncable
+
if syncable.is_a?(Family)
syncable
else