A platform for community discussion. Free, open, simple.
DEV: Add more info to N1 custom field error (#15670)
Martin Brennanc1ae214c7bb4
diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rbindex f073544dbb1..12b404b96e2 100644--- a/app/models/concerns/has_custom_fields.rb+++ b/app/models/concerns/has_custom_fields.rb@@ -160,9 +160,11 @@ module HasCustomFields@custom_fields_orig = nilend+ class NotPreloadedError < StandardError; endclass PreloadedProxy- def initialize(preloaded)+ def initialize(preloaded, klass_with_custom_fields)@preloaded = preloaded+ @klass_with_custom_fields = klass_with_custom_fieldsenddef [](key)@@ -170,14 +172,14 @@ module HasCustomFields@preloaded[key]else# for now you can not mix preload an non preload, it better just to fail- raise StandardError, "Attempted to access the non preloaded custom field '#{key}'. This is disallowed to prevent N+1 queries."+ raise NotPreloadedError, "Attempted to access the non preloaded custom field '#{key}' on the '#{@klass_with_custom_fields}' class. This is disallowed to prevent N+1 queries."endendenddef custom_fieldsif @preloaded_custom_fields- return @preloaded_proxy ||= PreloadedProxy.new(@preloaded_custom_fields)+ return @preloaded_proxy ||= PreloadedProxy.new(@preloaded_custom_fields, self.class.to_s)end@custom_fields ||= refresh_custom_fields_from_db.dup