From b8213b7855a8c57d1c5b1e114c01fc7f5c0c179e Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Fri, 24 May 2024 11:26:11 -0700 Subject: [PATCH 1/2] Ignore invalid associations --- CHANGELOG.md | 6 ++++++ VERSION | 2 +- lib/support_table_data.rb | 3 +++ spec/spec_helper.rb | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9acc2..4bc9941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.2.1 + +### Changed + +- Ignore invalid associations when inspecting reflections on `sync_all!` to establish the load order. These kinds of errors have nothing to do with the support table definition and create confusion when the are raised while syncing data. + ## 1.2.0 ### Added diff --git a/VERSION b/VERSION index 26aaba0..6085e94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.0 +1.2.1 diff --git a/lib/support_table_data.rb b/lib/support_table_data.rb index d008335..2de7e68 100644 --- a/lib/support_table_data.rb +++ b/lib/support_table_data.rb @@ -406,6 +406,9 @@ def support_table_dependencies(klass) next unless reflection.belongs_to? || reflection.through_reflection? dependencies << reflection.klass + rescue StandardError => e + message = "Error inspecting reflection #{reflection.name} on #{klass.name}: #{e.inspect}" + klass.logger&.warn(message) end dependencies diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4da7859..382258e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -57,6 +57,9 @@ class Color < ActiveRecord::Base has_many :things has_many :shades, through: :things + # Intentionally invalid association + belongs_to :non_existent, class_name: "NonExistent" + validates_uniqueness_of :name def group_name=(value) From 0578280623254c228a45ac32e997df71d95aa272 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Fri, 24 May 2024 11:28:11 -0700 Subject: [PATCH 2/2] code style --- lib/support_table_data.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/support_table_data.rb b/lib/support_table_data.rb index 2de7e68..7c52f05 100644 --- a/lib/support_table_data.rb +++ b/lib/support_table_data.rb @@ -406,7 +406,7 @@ def support_table_dependencies(klass) next unless reflection.belongs_to? || reflection.through_reflection? dependencies << reflection.klass - rescue StandardError => e + rescue => e message = "Error inspecting reflection #{reflection.name} on #{klass.name}: #{e.inspect}" klass.logger&.warn(message) end