Creating a host via API does not inherit Puppet Environment anymore

We have set default Puppet Environments in hostgroups to be inherited by hosts created in that HG. Since we updated our test environment from Foreman 2.5.4/Katello 4.1 to Foreman 3.2.1/Katello 4.4.1, this inheritance does not work anymore when creating hosts via API.
In 2.5, creating a host via API request inherited the environment from the HG if not explicitly sent, in 3.2 we end up with a host without assigned Puppet environment, breaking host installation workflows.
Creating a host manually via the UI still works, but I assume this is caused by the UI handling inheritance and host creation very differently.

Expected outcome:
Host is created with the Puppet environment inherited correctly from the hostgroup.

Foreman and Proxy versions:

Foreman and Proxy plugin versions:

 - foreman-tasks 6.0.1
 - foreman_bootdisk 19.0.3
 - foreman_expire_hosts 7.0.4
 - foreman_hooks 0.3.17
 - foreman_puppet 3.0.7
 - foreman_remote_execution 6.0.0
 - foreman_scc_manager 1.8.20
 - foreman_snapshot_management 2.0.1
 - foreman_templates 9.1.0
 - katello 4.4.1
 - puppetdb_foreman 5.0.0

Distribution and version:

Other relevant data:
Here is an example request as received by Foreman (from production.log) :

2022-08-24T09:56:59 [I|app|2e7b946c]   Parameters: {"host"=>{"name"=>"", "location_id"=>2, "organization_id"=>1, "compute_resource_id"=>4, "compute_profile_id"=>1, "hostgroup_id"=>202, "compute_attributes"=>{"cpus"=>1, "corespersocket"=>1, "memory_mb"=>3072, "extra_config"=>{"snapshot.alwaysAllowNative"=>true}}, "interfaces_attributes"=>[{"identifier"=>"eth0", "name"=>"server", "subnet_id"=>2, "domain_id"=>1, "managed"=>true, "provision"=>true, "primary"=>true, "compute_attributes"=>{"type"=>"VirtualVmxnet3", "network"=>"redacted"}}, {"identifier"=>"eth1", "name"=>"server-2nd-name", "subnet_id"=>32, "domain_id"=>1, "managed"=>true, "provision"=>false, "primary"=>false, "compute_attributes"=>{"type"=>"VirtualVmxnet3", "network"=>"redacted2"}}], "host_parameters_attributes"=>[{"name"=>"owner_mail", "value"=>"[FILTERED]"}, {"name"=>"ticketnr", "value"=>"[FILTERED]"}], "lookup_values_attributes"=>"[FILTERED]", "build"=>true}, "apiv"=>"v2"}

I would assume this is somehow caused by the Puppet ENC extraction, but since I could find absolutly no bug reports about this, maybe something on our end broke.
If you need any more info/logs, let me know.

Regards :slight_smile:

We found out this only happens if the hostgroup itself inherits the environment from a parent hostgroup.
We can live with this as workaround (setting all puppet environments explicitly in every hostgroup), but imo this should still be fixed.