You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The protected write_attribute method of SparkApi::Models::Base checks whether the value being set for an attribute is already set to the assigned value. This causes inconsistent behavior when the attribute is new and the assigned value is nil because attributes is a hash and returns nil when a key does not exist.
l=SparkApi::Models::Listing.newl.attributes# {}l.City# NoMethodError: undefined method `include?' for nil:NilClassl.State='ND'l.City=nill.State# "ND"l.City# NoMethodError: undefined method `include?' for nil:NilClassl.attributes# {"State"=>"ND"}l.attributes['City']=nill.City# nill.attributes# {"State"=>"ND", "City"=>nil}l.changes#{"State"=>[nil, "ND"]}
This can be partially worked around by writing to the attributes hash directly. However, as illustrated above, that isn't a full-featured approach with respect to the SparkApi::Models::Dirty module at least.
On second thought, l.changes isn't a great example of the workaround not being full-featured. However, the general point remains that this is inconsistent behavior.
The text was updated successfully, but these errors were encountered:
The protected
write_attribute
method ofSparkApi::Models::Base
checks whether the value being set for an attribute is already set to the assigned value. This causes inconsistent behavior when the attribute is new and the assigned value isnil
becauseattributes
is a hash and returnsnil
when a key does not exist.This can be partially worked around by writing to the
attributes
hash directly. However, as illustrated above, that isn't a full-featured approach with respect to theSparkApi::Models::Dirty
module at least.On second thought,
l.changes
isn't a great example of the workaround not being full-featured. However, the general point remains that this is inconsistent behavior.The text was updated successfully, but these errors were encountered: