graphiti
graphiti copied to clipboard
Fix RTE in ActiveRecord adapter when using null string filter
If one's resource is backed by ActiveRecord, an RTE is thrown if one allows nil and tries to filter by null on a string value. The adapter maps the filter values with downcase
without checking for nil.
@richmolj
Thanks so much! Would you mind adding a test for this and I will merge?
Not ready yet, something is differing between how the appraisal spec and our (older) monkeypatched version of Graphiti is constructing the eq: 'null'
clause.
Monkeypatched version clause (correct behavior, see last line)
=> #<Arel::Nodes::Grouping:0x0000000010b16b50
@expr=
#<Arel::Nodes::Equality:0x0000000010b16c40
@left=
#<Arel::Nodes::NamedFunction:0x0000000010b17460
@alias=nil,
@distinct=false,
@expressions=
[#<struct Arel::Attributes::Attribute
relation=
#<Arel::Table:0x0000000018da0ff8
@name="monkeypatched_resource",
@table_alias=nil,
@type_caster=
#<ActiveRecord::TypeCaster::Map:0x0000000018da1048
@types= <list of attributes>
@name="LOWER">,
@right=
#<Arel::Nodes::Quoted:0x0000000010b16c90
@expr=nil>>>
Spec version clause (last line expression is "null" not nil)
=> #<Arel::Nodes::Grouping:0x00007f885dcc3318
@expr=
#<Arel::Nodes::Equality:0x00007f885dcc3390
@left=
#<Arel::Nodes::NamedFunction:0x00007f885dcc34d0
@alias=nil,
@distinct=false,
@expressions=
[#<struct Arel::Attributes::Attribute
relation=
#<Arel::Table:0x00007f883db737f8
@name="authors",
@table_alias=nil,
@type_caster=
#<ActiveRecord::TypeCaster::Map:0x00007f883db73848
@types=
Legacy::Author(id: integer, active: boolean, first_name: string, last_name: string, age: integer, float_age: float, decimal_age: float, dwelling_type: string, state_id: integer, dwelling_id: integer, organization_id: integer, created_at_date: date, last_login: datetime, identifier: string, created_at: datetime, updated_at: datetime)>>,
name=:last_name>],
@name="LOWER">,
@right=#<Arel::Nodes::Quoted:0x00007f885dcc33e0 @expr="null">>>