Bug #17360

Filter on FactValue with like-search fails with "malformed format string - % (ArgumentError)"

Added by Sebastian Bublitz over 1 year ago. Updated 12 months ago.

Assigned To:Kavita Gaikwad
Target version:Team Anurag Iteration 18
Difficulty: Bugzilla link:
Found in release:1.12.4 Pull request:https://github.com/theforeman/foreman/pull/4664
Story points-
Velocity based estimate-
Release1.16.0Release relationshipAuto


Hi everyone,

I have been trying to create a filter for a role on the FactValue resource.
Applying filters with equals operator works perfectly fine, but filtering with a like search raises a "malformed format string - %k (ArgumentError)".
This happens both via WebUI and via hammer.
Here is the stacktrace hammer shows me when updating the filter via "hammer filter update --id <id> --search 'host ~ <name>'":

/opt/theforeman/tfm/root/usr/share/gems/gems/fast_gettext-1.1.0/lib/fast_gettext/vendor/string.rb:70:in `%': malformed format string - %k (ArgumentError)
from /opt/theforeman/tfm/root/usr/share/gems/gems/fast_gettext-1.1.0/lib/fast_gettext/vendor/string.rb:70:in `%'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/utils.rb:12:in `format'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/output/adapter/abstract.rb:32:in `print_error'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/output/output.rb:16:in `print_error'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/exception_handler.rb:45:in `print_error'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/exception_handler.rb:62:in `handle_general_exception'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/exception_handler.rb:28:in `handle_exception'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/abstract.rb:189:in `handle_exception'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/abstract.rb:26:in `rescue in run'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/lib/hammer_cli/abstract.rb:22:in `run'
from /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.0.0/lib/clamp/command.rb:133:in `run'
from /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.7.0/bin/hammer:125:in `<top (required)>'
from /bin/hammer:23:in `load'
from /bin/hammer:23:in `<main>'

The same error message (malformed format string - %k) appears in the WebUI when applying a like filter on the facts page in the filter box, or when searching facts via hammer with a like search.

This was tested on Katello 3.1/Foreman 1.12.4, but since I could not find a ticket for this issue, I'm assuming this bug is still around.

Associated revisions

Revision bcb74718
Added by Kavita Gaikwad 12 months ago

Fixes #17360 - Prevent % string interpolation in scoped_search


#1 Updated by Dominic Cleal over 1 year ago

  • Category set to Search

Trivially reproducible with:

$ bin/rails runner "FactValue.search_for('host ~ a')" 
Running via Spring preloader in process 26304
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/fast_gettext-1.1.0/lib/fast_gettext/vendor/string.rb:70:in `%': too few arguments (ArgumentError)
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/fast_gettext-1.1.0/lib/fast_gettext/vendor/string.rb:70:in `%'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activerecord- `sanitize_sql_array'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activerecord- `sanitize_sql_for_conditions'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activerecord- `build_where'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activerecord- `where!'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activerecord- `where'
        from /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/scoped_search-3.3.0/lib/scoped_search/definition.rb:268:in `block in register_named_scope!'

I suspect the stack trace above could be issue #11178 where the error message is being misinterpreted, and the root cause is something more similar to the search above failing.

#2 Updated by Kavita Gaikwad about 1 year ago

  • Assigned To set to Kavita Gaikwad

#3 Updated by The Foreman Bot 12 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4664 added

#4 Updated by Kavita Gaikwad 12 months ago

  • Target version set to Team Anurag Iteration 18

#5 Updated by Tomer Brisker 12 months ago

  • Release set to 1.16.0

#6 Updated by Kavita Gaikwad 12 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF