graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

Fix RTE in ActiveRecord adapter when using null string filter

Open smai-f opened this issue 2 years ago • 2 comments

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

smai-f avatar Apr 11 '22 20:04 smai-f

Thanks so much! Would you mind adding a test for this and I will merge?

richmolj avatar May 10 '22 20:05 richmolj

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">>>

smai-f avatar Jul 28 '22 23:07 smai-f