{"action":"opened","issue":{"url":"https://api.github.com/repos/chef/chef/issues/5612","repository_url":"https://api.github.com/repos/chef/chef","labels_url":"https://api.github.com/repos/chef/chef/issues/5612/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/5612/comments","events_url":"https://api.github.com/repos/chef/chef/issues/5612/events","html_url":"https://github.com/chef/chef/issues/5612","id":193546284,"number":5612,"title":"Chef::DataBagItem.destroy using wrong uri against chef server","user":{"login":"jrmuir","id":8453347,"avatar_url":"https://avatars.githubusercontent.com/u/8453347?v=3","gravatar_id":"","url":"https://api.github.com/users/jrmuir","html_url":"https://github.com/jrmuir","followers_url":"https://api.github.com/users/jrmuir/followers","following_url":"https://api.github.com/users/jrmuir/following{/other_user}","gists_url":"https://api.github.com/users/jrmuir/gists{/gist_id}","starred_url":"https://api.github.com/users/jrmuir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrmuir/subscriptions","organizations_url":"https://api.github.com/users/jrmuir/orgs","repos_url":"https://api.github.com/users/jrmuir/repos","events_url":"https://api.github.com/users/jrmuir/events{/privacy}","received_events_url":"https://api.github.com/users/jrmuir/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-05T16:34:02Z","updated_at":"2016-12-05T16:34:02Z","closed_at":null,"body":"## Description\r\n\r\nAttempting to leverage Chef::DataBagItem destroy instance method results in a 404.  Loading and saving the same instance works correctly.\r\n\r\n## Chef Version\r\n\r\nChef Client, version 12.16.42\r\nChef Server, version 12.11.1\r\n\r\n## Platform Version\r\n\r\nRed Hat Enterprise Linux 6 and 7\r\n\r\n## Replication Case\r\n\r\nCreate a data bag and item on a chef server.  Load a data bag item.  Attempt to destroy within a recipe (with correct ACLS set).\r\n\r\n## Client Output\r\n\r\n```\r\n[2016-12-05T08:19:48-07:00] DEBUG: Chef::HTTP calling Chef::HTTP::RemoteRequestID#handle_request\r\n[2016-12-05T08:19:48-07:00] DEBUG: Chef::HTTP calling Chef::HTTP::ValidateContentLength#handle_request\r\n[2016-12-05T08:19:48-07:00] DEBUG: Initiating DELETE to https://chef-server/organizations/myorg/data/aws_vpc/data_bag_item_aws_vpc_wordpress-vpc0644384204\r\n[2016-12-05T08:19:48-07:00] DEBUG: ---- HTTP Request Header Data: ----\r\n[2016-12-05T08:19:48-07:00] DEBUG: X-REMOTE-REQUEST-ID: 39a7f3cf-7188-4c43-afbb-f0445fed9fdd\r\n...\r\n[2016-12-05T08:19:48-07:00] DEBUG: ---- End HTTP Request Header Data ----\r\n[2016-12-05T08:19:48-07:00] DEBUG: ---- HTTP Status and Header Data: ----\r\n[2016-12-05T08:19:48-07:00] DEBUG: HTTP 1.1 404 Object Not Found: error\r\n```\r\n\r\nNote that when loading or saving, it references https://chef-server/organizations/myorg/data/aws_vpc/wordpress-vpc0644384204 and setting a chef_server_rest instance similar to Chef::DataBagItem and running the delete with the proper name works correctly.\r\n\r\ni.e.:\r\n```\r\nchef_server_rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url])\r\nchef_server_rest.delete(\"data/#{databag}/#{key}\")\r\n```\r\nWhere databag represents the name of the databag and key represents the item name - aws_vpc and wordpress-vpc0644384204 respectively in this instance.\r\n\r\n## Stacktrace\r\n\r\nn/a, debug above should suffice to highlight the problem\r\n\r\n### NOTE: CHEF CLIENT BUGS ONLY\r\n\r\nBased off the behavior of the recipe, I believe this applies only to chef-client against a server but is not a server bug.  The offending issue appears to be leveraging self.object_name for the data bag item id instead of the actual data bag item id at https://github.com/chef/chef/blob/af1332711139cade37104169e943e290c6c00362/lib/chef/data_bag_item.rb lines 167-169\r\n\r\nChanging \r\n`def destroy(data_bag=data_bag(), databag_item=name)`\r\nto \r\n`def destroy(data_bag=data_bag(), databag_item=id)`\r\nshould be sufficient to resolve, though databag_item might need to be set to @raw_data[\"id\"]\r\n\r\n"}}
{"actor":{"display_login":"jrmuir"}}