Skip to content

Commit 2dd4659

Browse files
committed
[*] Records Display - Ensure that the data is properly sent even if an attribute serialization happens for an unknown reason
1 parent 45ba331 commit 2dd4659

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## [Unreleased]
4+
### Fixed
5+
- Records Display - Ensure that the data is properly sent even if an attribute serialization happens for an unknown reason.
46

57
## RELEASE 2.15.5 - 2019-02-27
68
### Fixed

app/serializers/forest_liana/serializer_factory.rb

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,27 @@ def mixpanel_integration?
179179

180180
unless @is_smart_collection
181181
attributes(active_record_class).each do |attribute|
182-
serializer.attribute(attribute)
182+
serializer.attribute(attribute) do |x|
183+
begin
184+
object.send(attribute)
185+
rescue
186+
nil
187+
end
188+
end
183189
end
184190

185191
# NOTICE: Format time type fields during the serialization.
186192
attributes_time(active_record_class).each do |attribute|
187193
serializer.attribute(attribute) do |x|
188-
value = object.send(attribute)
189-
if value
190-
match = /(\d{2}:\d{2}:\d{2})/.match(value.to_s)
191-
(match && match[1]) ? match[1] : nil
192-
else
194+
begin
195+
value = object.send(attribute)
196+
if value
197+
match = /(\d{2}:\d{2}:\d{2})/.match(value.to_s)
198+
(match && match[1]) ? match[1] : nil
199+
else
200+
nil
201+
end
202+
rescue
193203
nil
194204
end
195205
end
@@ -198,22 +208,38 @@ def mixpanel_integration?
198208
# NOTICE: Format serialized fields.
199209
attributes_serialized(active_record_class).each do |attr, serialization|
200210
serializer.attribute(attr) do |x|
201-
value = object.send(attr)
202-
value ? value.to_json : nil
211+
begin
212+
value = object.send(attr)
213+
value ? value.to_json : nil
214+
rescue
215+
nil
216+
end
203217
end
204218
end
205219

206220
# NOTICE: Format CarrierWave url attribute
207221
if active_record_class.respond_to?(:mount_uploader)
208222
active_record_class.uploaders.each do |key, value|
209-
serializer.attribute(key) { |x| object.send(key).try(:url) }
223+
serializer.attribute(key) do |x|
224+
begin
225+
object.send(key).try(:url)
226+
rescue
227+
nil
228+
end
229+
end
210230
end
211231
end
212232

213233
# NOTICE: Format Paperclip url attribute
214234
if active_record_class.respond_to?(:attachment_definitions)
215235
active_record_class.attachment_definitions.each do |key, value|
216-
serializer.attribute(key) { |x| object.send(key) }
236+
serializer.attribute(key) do |x|
237+
begin
238+
object.send(key)
239+
rescue
240+
nil
241+
end
242+
end
217243
end
218244
end
219245

@@ -223,7 +249,11 @@ def mixpanel_integration?
223249
active_record_class.acts_as_taggable.respond_to?(:to_a)
224250
active_record_class.acts_as_taggable.to_a.each do |key, value|
225251
serializer.attribute(key) do |x|
226-
object.send(key).map(&:name)
252+
begin
253+
object.send(key).map(&:name)
254+
rescue
255+
nil
256+
end
227257
end
228258
end
229259
end
@@ -277,8 +307,7 @@ def mixpanel_integration?
277307
serializer.send(:has_many, :mixpanel_last_events) { }
278308
end
279309

280-
ForestLiana::SerializerFactory.define_serializer(active_record_class,
281-
serializer)
310+
ForestLiana::SerializerFactory.define_serializer(active_record_class, serializer)
282311

283312
serializer
284313
end

0 commit comments

Comments
 (0)