Skip to content

Non-existent filter arguments #585

@smcabrera

Description

@smcabrera

I'm using ActiveInteraction 5.5.0

Filters will allow you to include keyword arguments that don't exist:

class MyInteraction < ActiveInteraction::Base
  string :beverage, type: :sparkling_wine, bubbles: true

  def execute
    puts "Enjoy your #{beverage}!"
  end
end

MyInteraction.run!(beverage: 'Cava')

While these vestigial arguments are mostly harmless it could confuse people if they misunderstand the docs or misspell something and then wonder why it doesn't work as they expect

class SquareIds < ActiveInteraction::Base
  array :ids, type: :integer, descl: 'Documentation of this filter'

  def execute
    puts ids.map { _1 ** 2 } 
  end
end

SquareIds.run!(ids: [1, 2, 'BAD'])
# bin/script:15:in `block in execute': undefined method `**' for an instance of String (NoMethodError)

A user might think "Why didn't my type checking protect me?" when really it's because type doesn't exist. They should have done:

array :ids do
  integer
end

But instead they misremembered (or perhaps an LLM hallucinated 😅) there being a type kwarg.

Why isn't the documentation they wrote present? Well they just misspelled desc as descl...but we didn't yell at them.

I haven't dug into the source yet but I'm guessing if we were to add an allowlist to check keywords against we could ensure that only kwargs that actually do something are let through. Assuming maintainers think that's desirable? It could be a breaking change but hopefully not a hard one for users to address (remove your keyword arguments that weren't doing anything in the first place?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions