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
id_or_value.to_i within Aggregate::ForeignKeyReference#initialize can cause an empty string given as an id to be stored as 0. This 0 will then be stored as the aggregate_belongs_to attribute's ID in serialized storage data. This means that trying to fetch the associated DB record will (most likely always) raise an exception because the record won't be found, which ends up becoming confusing to debug because it's not necessarily clear to the consumer of the gem why 0 is being stored as the ID.
omeedrj
changed the title
Giving an empty string as the foreign key ID for an aggregate_belongs_to attribute stores the ID as 0
Empty string given as the foreign key ID for an aggregate_belongs_to attribute ends up storing the ID as 0
Oct 22, 2021
Description
id_or_value.to_i
withinAggregate::ForeignKeyReference#initialize
can cause an empty string given as an id to be stored as0
. This0
will then be stored as theaggregate_belongs_to
attribute's ID in serialized storage data. This means that trying to fetch the associated DB record will (most likely always) raise an exception because the record won't be found, which ends up becoming confusing to debug because it's not necessarily clear to the consumer of the gem why0
is being stored as the ID.aggregate/lib/aggregate/foreign_key_reference.rb
Line 13 in edd6252
Example
Suggested Fix
id_or_value
is not anActiveRecord::Base
object, we should raise anArgumentError
ifid_or_value
isnil
or an empty stringThe text was updated successfully, but these errors were encountered: