Bug 1618378

Summary: 1.17 migration causes array/hash values for parameters to turn into strings with escaped quotes
Product: Red Hat Satellite Reporter: Tomer Brisker <tbrisker>
Component: Smart VariablesAssignee: Tomer Brisker <tbrisker>
Status: CLOSED ERRATA QA Contact: Jitendra Yejare <jyejare>
Severity: high Docs Contact:
Priority: high    
Version: NightlyCC: bkearney, inecas, orabin, sghai, zhunting
Target Milestone: 6.4.0Keywords: Regression, Triaged, Upgrades
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-1.18.0.10-1 Doc Type: Known Issue
Doc Text:
Users who have used complex values for parameters will get an error during upgrade of the beta. If this is encountered, please reach out to support for a fix.
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-16 18:55:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tomer Brisker 2018-08-16 14:00:35 UTC
Looks like an issue in db/migrate/20170112175131_migrate_template_to_parameters_macros.rb causes any such lookupkeys/lookupvalues to turn their values to strings. 
Since the values are saved using update_attribute, callbacks aren't executed meaning cast_default_value is not called and the value remains a string.

For example:
<pre>
#<VariableLookupKey:0x0000000015b50738
 id: 21532,
 key: "zdcaz",
 created_at: Thu, 16 Aug 2018 13:01:56 UTC +00:00,
 updated_at: Thu, 16 Aug 2018 13:01:56 UTC +00:00,
 puppetclass_id: 5,
 default_value: ["a", "b"],
 path: nil,
 description: "",
 validator_type: "",
 validator_rule: nil,
 key_type: "array",
 override: false,
 required: false,
 merge_overrides: false,
 avoid_duplicates: false,
 omit: nil,
 type: "VariableLookupKey",
 merge_default: false,
 hidden_value: false>
[152] pry(main)> k.default_value = convert(k.default_value.to_s)
=> "[\"a\", \"b\"]"
</pre>

As a workaround, it may be possible to iterate over all Lookupkeys and values and save them all again to ensure casting is called from foreman-rake console (please take care to backup your database before running this):
<pre>
LookupKey.unscoped.find_each(&:save_without_auditing)
</pre>

Comment 1 Tomer Brisker 2018-08-16 14:00:41 UTC
Created from redmine issue http://projects.theforeman.org/issues/24640

Comment 2 Tomer Brisker 2018-08-16 14:00:46 UTC
Upstream bug assigned to tbrisker

Comment 5 Satellite Program 2018-08-20 16:06:08 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/24640 has been resolved.

Comment 8 Jitendra Yejare 2018-09-02 05:19:27 UTC
Verified!

@ Satellite 6.4 snap 19

Steps:

1. Created various and all types of class parameters before the upgrade.
2. Ran upgrade from 6.3.3-2 to 6.4.

Observation:

1. Upgrade completed successfully without any errors.
2. Also, the data and types of class parameters are intact after the upgrade.

Hence, changing the bug status to Verified.

Comment 9 Bryan Kearney 2018-10-16 18:55:13 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927