Created attachment 890865 [details] part of /var/log/foreman/production.log Description of problem: Creation of an user via API with default_organization_id set fails with 500 ISE. Version-Release number of selected component (if applicable): Satellite-6.0.3-RHEL-6-20140423.1-Satellite-x86_64-dvd1.iso How reproducible: always Steps to Reproduce: 1. Run @api.resource(:users).call(:create, user_hash) with following user_hash: user_hash = { :login => "newuser", :firstname => "user", :lastname => "new", :mail => "root@localhost", :auth_source_id => 1, :password => "password", :organization_ids => [13], :default_organization_id => 13, :location_ids => [], :role_ids => [], } Actual results: Creation of user failed with: 500 Internal Server Error: { "error": {"message":"undefined method `key?' for #<JSON::Ext::Generator::State:0x007f696cecadd8>"} } *but* the user was created! Expected results: no exceptions or ISEs Additional info: - creating of the user without default_organization_id works and setting it using the user update API afterwards works as well
Since this issue was entered in Red Hat Bugzilla, the release flag has been set to ? to ensure that it is properly evaluated for this release.
redmine issue created
Hi Tomas, I tested the call with what's out on upstream. The issue may have been solved already. ISE is no longer given and a proper validation message is given. Is this behavior fine? See examples of behavior on the latest upstream code. https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb
Hello Dustin, as this BZ is filed against Satellite 6, it's determinative, when the BZ will be fixed in Satellite 6. Checking your examples you're not getting an ISE anymore, but you're still not able to create a user with a default organization set. I'm not sure what does "Default organization Default organizations need to be user organizations first" mean (and this might be what I'm missing), but if I'm able to create a user with default organization set via WebUI, I'd expect to be able to do it similarly via API as well.
removing association to redmine issue, will create a new issue lateer if necessary.
Tomas, Sorry, it wasn't too clear the way I put everything into one gist like that. If you see the very last example starting at line 100 (https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L100), I was able to create a default organization successfully. I think the validation message could be clearer. The validation is trying to prevent setting a default organization that doesn't have an association with the user; The default organization being set must also be part of organizations being passed in creation so that the association to the default organization is created. (see lines 105,106 https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L105) would it be sufficient to make update the validation message?
Tomas, Sorry, it wasn't too clear the way I put everything into one gist like that. If you see the very last example starting at line 100 (https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L100), I was able to create a default organization successfully. I think the validation message could be clearer. The validation is trying to prevent setting a default organization that doesn't have an association with the user; The default organization being set must also be part of organizations being passed in creation so that the association to the default organization is created. (see lines 105,106 https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L105) would it be sufficient to make an update to the validation message?
Hello Dustin, thank you for the explanation. So, your first call at line 23, where you miss an extra "user" hash within the user_hash should say something else (in case the extra "user" hash is required) Your second call at line 66 fails because the organization you want to set as default_organization isn't a user organization already. I am totally ok with the error message/exception thrown. The last call at line 109 succeeds, so it's ok. Just note you set strings ("1") as organization ids instead of integers (1).
Hi Tomas, We can't really provide validation for user_hash to be provided since it really is an optional param to be passed in. Some params like search/pagination can come in as top-level params. I'm gonna mark it as post.
jason, closing as WONTFIX.
Hello Dustin, I do not know the code to confront Comment 10. From user perspective, it's possible to set the default_organization_id at user creation via WEBUI. Why isn't the same possible via API? Cannot the same code be reused?