AE
Ash Elixir•3y ago
dblack

FilterForm inspect strange behavior

I'm just playing around with FilterForm and I'm seeing some weird inspect behavior, which is not making it easy to reason with what's going on. For instance:
filter_form = FilterForm.new(Property)
{filter_form, group_id} = FilterForm.add_group(filter_form, operator: :or, return_id?: true)
filter_form = FilterForm.add_predicate(filter_form, :id, :eq, nil, to: group_id)

IO.inspect(filter_form)
filter_form = FilterForm.new(Property)
{filter_form, group_id} = FilterForm.add_group(filter_form, operator: :or, return_id?: true)
filter_form = FilterForm.add_predicate(filter_form, :id, :eq, nil, to: group_id)

IO.inspect(filter_form)
Gives me:
%AshPhoenix.FilterForm.Predicate{
id: "0b9cab33-2194-475e-a010-407d5964a8ec",
field: :id,
value: nil,
transform_errors: nil,
operator: :eq,
params: %{
"field" => :id,
"id" => "0b9cab33-2194-475e-a010-407d5964a8ec",
"operator" => :eq,
"value" => nil
},
arguments: %AshPhoenix.FilterForm.Arguments{
input: %{},
params: %{},
arguments: [],
errors: []
},
negated?: false,
path: [],
errors: [],
valid?: true
}
%AshPhoenix.FilterForm.Predicate{
id: "0b9cab33-2194-475e-a010-407d5964a8ec",
field: :id,
value: nil,
transform_errors: nil,
operator: :eq,
params: %{
"field" => :id,
"id" => "0b9cab33-2194-475e-a010-407d5964a8ec",
"operator" => :eq,
"value" => nil
},
arguments: %AshPhoenix.FilterForm.Arguments{
input: %{},
params: %{},
arguments: [],
errors: []
},
negated?: false,
path: [],
errors: [],
valid?: true
}
I would have expected a FilterForm struct. I've validated that filter_form is actually a FilterForm and not a FilterForm.Predicate? Is this a bug with the inspect protocol for FilterForm's or am I totally misunderstanding something (likely)!
9 Replies
ZachDaniel
ZachDaniel•3y ago
Strange... we don't have define an inspect impl I don't think
dblack
dblackOP•3y ago
yeah. i've tried blowing away _build... and same behaviour
ZachDaniel
ZachDaniel•3y ago
So if you do IO.inspect(filter_form, structs: false) what do you see? how have you verified that it is a FilterForm
dblack
dblackOP•3y ago
%FilterForm.Predicate{} = filter_form bombs, and FilterForm doesn't Would that do it?
ZachDaniel
ZachDaniel•3y ago
šŸ¤” yeah probably
dblack
dblackOP•3y ago
and structs: false is no different
ZachDaniel
ZachDaniel•3y ago
okay so in that case there has to be some kind of user error šŸ˜†
dblack
dblackOP•3y ago
issue solved! yeah let me look through what I'm doing šŸ¤¦ā€ā™‚ļø user error, thanks and apologies
ZachDaniel
ZachDaniel•3y ago
no worries

Did you find this page helpful?