Jira (PUP-11237) Util::JSON.dump receives non-hash options

25 views
Skip to first unread message

Lucy Voigt (Jira)

unread,
Sep 3, 2021, 11:14:03 AM9/3/21
to puppe...@googlegroups.com
Lucy Voigt created an issue
 
Puppet / Bug PUP-11237
Util::JSON.dump receives non-hash options
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2021/09/03 8:13 AM
Priority: Normal Normal
Reporter: Lucy Voigt

Puppet Version: Main branch (401e01b2691d9c496749ff07f7fca7fc852e105c)
Puppet Server Version: Main branch (38479aafcb6c27d826976e31a993258e9e9e4de2)
OS Name/Version: Ubuntu 20.04

While testing the file_metadatas Puppetserver endpoint, when sending this request:
code
https://localhost:8140/puppet/v3/file_metadatas/scripts/mymodule/script.sh?environment=production&recurse=yes
code
Puppet errors with (apologies for the backtrace!):
code
2021-09-03 07:58:27,688 DEBUG [qtp1541353205-57] [puppetserver] Puppet Could not render_multiple to Puppet::Network::Format[json]: undefined method `delete' for #<JSON::Ext::Generator::State:0x79067448>
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/util/json.rb:64:in `dump'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/format_support.rb:105:in `to_json'
json/ext/GeneratorMethods.java:79:in `to_json'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/util/json.rb:65:in `dump'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/formats.rb:129:in `render_multiple'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/format_support.rb:26:in `render_multiple'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:161:in `block in do_search'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:192:in `block in first_response_formatter_for'
org/jruby/RubyEnumerable.java:690:in `find'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:190:in `first_response_formatter_for'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:160:in `do_search'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:53:in `block in call'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/context.rb:62:in `override'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet.rb:306:in `override'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/indirected_routes.rb:52:in `call'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/api/server/v3.rb:17:in `block in wrap'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/route.rb:82:in `block in process'
org/jruby/RubyArray.java:1809:in `each'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/route.rb:81:in `process'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/route.rb:88:in `process'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/route.rb:88:in `process'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:86:in `block in process'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:69:in `block in with_request_profiling'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/util/profiler.rb:51:in `profile'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:65:in `with_request_profiling'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:85:in `block in process'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:92:in `respond_to_errors'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/network/http/handler.rb:84:in `process'
uri:classloader:/puppetserver-lib/puppet/server/master.rb:69:in `block in handleRequest'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet/context.rb:62:in `override'
/home/lucy/githubs/puppetserver/ruby/puppet/lib/puppet.rb:306:in `override'
uri:classloader:/puppetserver-lib/puppet/server/master.rb:68:in `handleRequest'
code

This only happens when requesting the scripts mount - the request
code
https://localhost:8140/puppet/v3/file_metadatas/modules/mymodule/file?environment=production&recurse=yes
code
behaves as expected.

The object that dump is receiving in this case actually can be converted to a hash, and adding
code
options = options.to_h unless options.is_a?(Hash)
code
fixes the issue, but doesn't really get to why this method is receiving the wrong object to begin with.

Happy to provide more testing and info!

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Cas Donoghue (Jira)

unread,
Sep 8, 2021, 1:13:02 PM9/8/21
to puppe...@googlegroups.com

Cas Donoghue (Jira)

unread,
Sep 8, 2021, 1:13:02 PM9/8/21
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Skeletor - 09/22/2021

Cas Donoghue (Jira)

unread,
Sep 8, 2021, 1:13:02 PM9/8/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Sep 9, 2021, 2:58:03 AM9/9/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11237
 
Re: Util::JSON.dump receives non-hash options

This is an old issue introduced in PUP-8501, but it only occurs when the multi_json gem is not installed, such as when running puppetserver from source. The problem is Puppet::Network::FormatSupport overrides the to_json method originally monkey patched by the JSON library. Then FormatSupport is mixed into all indirected models like Puppet::FileServing::Metadata. So when Puppet::Util::Json.dump calls to_json it's calling the wrong method. The flow goes like:

Format#render_multiple(Array<Metadata>)
Puppet::Util::Json.dump(Array<Metadata>, Hash)
Array#to_json(Hash)
FormatSupport#to_json(options) # this is where things go bad
Puppet::Util::Json.dump(Hash)

FWIW this isn't an issue when running from puppetserver packages, because the multi_json gem is installed.

Josh Cooper (Jira)

unread,
Sep 10, 2021, 2:05:03 PM9/10/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11237

Lucy Voigt oh ha! I submitted a PR and just noticed it's in your sprint. Let me know if that fixes the issue?

Josh Cooper (Jira)

unread,
Sep 10, 2021, 2:06:02 PM9/10/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Change By: Josh Cooper
Fix Version/s: PUP 7.12.0
Fix Version/s: PUP 6.25.0

Josh Cooper (Jira)

unread,
Sep 13, 2021, 5:12:02 PM9/13/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Sep 15, 2021, 1:16:05 PM9/15/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Release Notes: Bug Fix
Release Notes Summary: Puppet's /puppet/v3/file_metadatas REST API would fail if the multi_json gem was uninstalled or when running puppetserver from source.

Claire Cadman (Jira)

unread,
Oct 5, 2021, 8:18:02 AM10/5/21
to puppe...@googlegroups.com
Claire Cadman updated an issue
Change By: Claire Cadman
Labels: doc-reviewed
Reply all
Reply to author
Forward
0 new messages