{"action":"opened","issue":{"url":"https://api.github.com/repos/Kong/kong/issues/3911","repository_url":"https://api.github.com/repos/Kong/kong","labels_url":"https://api.github.com/repos/Kong/kong/issues/3911/labels{/name}","comments_url":"https://api.github.com/repos/Kong/kong/issues/3911/comments","events_url":"https://api.github.com/repos/Kong/kong/issues/3911/events","html_url":"https://github.com/Kong/kong/issues/3911","id":374081701,"node_id":"MDU6SXNzdWUzNzQwODE3MDE=","number":3911,"title":"Error deleting services when running Kong with Cassandra database","user":{"login":"SravanYedhoti","id":21176831,"node_id":"MDQ6VXNlcjIxMTc2ODMx","avatar_url":"https://avatars2.githubusercontent.com/u/21176831?v=4","gravatar_id":"","url":"https://api.github.com/users/SravanYedhoti","html_url":"https://github.com/SravanYedhoti","followers_url":"https://api.github.com/users/SravanYedhoti/followers","following_url":"https://api.github.com/users/SravanYedhoti/following{/other_user}","gists_url":"https://api.github.com/users/SravanYedhoti/gists{/gist_id}","starred_url":"https://api.github.com/users/SravanYedhoti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SravanYedhoti/subscriptions","organizations_url":"https://api.github.com/users/SravanYedhoti/orgs","repos_url":"https://api.github.com/users/SravanYedhoti/repos","events_url":"https://api.github.com/users/SravanYedhoti/events{/privacy}","received_events_url":"https://api.github.com/users/SravanYedhoti/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-25T18:47:58Z","updated_at":"2018-10-25T18:47:58Z","closed_at":null,"author_association":"NONE","body":"### Summary\r\n\r\nWhen using Kong with Cassandra database and without enabling `oauth2` plugin, the service deletion is throwing error. The Cassandra service deletion is trying to cascade delete the service from `oauth2_tokens` and `oauth2_authorization_codes` tables [here](https://github.com/Kong/kong/blob/0.14.1/kong/db/strategies/cassandra/services.lua#L64-L65), since the `oauth2` plugin is not enabled those tables are missing and executing a DELETE statement with missing tables is causing an error.\r\n\r\n### Steps To Reproduce\r\n\r\n1. Run Kong with Cassandra database and don't include `oauth2` plugin in `KONG_PLUGINS`\r\n```\r\n# Start Cassandra docker instance\r\ndocker run -d --name kong-database -p 9042:9042 cassandra:3\r\n\r\n# Run Kong migrations without oauth2 plugin\r\ndocker run --rm \\\r\n    --link kong-database:kong-database \\\r\n    -e \"KONG_DATABASE=cassandra\" \\\r\n    -e \"KONG_CASSANDRA_CONTACT_POINTS=kong-database\" \\\r\n    -e \"KONG_PLUGINS=prometheus\" \\\r\n    -e \"KONG_DB_UPDATE_PROPAGATION=3\" \\\r\n    kong:0.14.1-centos kong migrations up\r\n\r\n# Run Kong without oauth2 plugin\r\ndocker run -d --name kong \\\r\n    --link kong-database:kong-database \\\r\n    -e \"KONG_DATABASE=cassandra\" \\\r\n    -e \"KONG_CASSANDRA_CONTACT_POINTS=kong-database\" \\\r\n    -e \"KONG_DB_UPDATE_PROPAGATION=3\" \\\r\n    -e \"KONG_ADMIN_LISTEN=0.0.0.0:8001\" \\\r\n    -e \"KONG_PROXY_ACCESS_LOG=/dev/stdout\" \\\r\n    -e \"KONG_ADMIN_ACCESS_LOG=/dev/stdout\" \\\r\n    -e \"KONG_PROXY_ERROR_LOG=/dev/stderr\" \\\r\n    -e \"KONG_ADMIN_ERROR_LOG=/dev/stderr\" \\\r\n    -e \"KONG_PLUGINS=prometheus\" \\\r\n    -p 8000:8000 \\\r\n    -p 8443:8443 \\\r\n    -p 8001:8001 \\\r\n    -p 8444:8444 \\\r\n    kong:0.14.1-centos\r\n```\r\n2. Create a service using the admin api\r\n```\r\ncurl -X POST http://localhost:8001/services \\\r\n  -H 'Content-Type: application/json' \\\r\n  -d '{\r\n    \"host\": \"localhost\",\r\n    \"connect_timeout\": 600000,\r\n    \"protocol\": \"http\",\r\n    \"name\": \"test\",\r\n    \"read_timeout\": 600000,\r\n    \"port\": 9000,\r\n    \"path\": null,\r\n    \"retries\": 0,\r\n    \"write_timeout\": 60000\r\n}'\r\n```\r\n3. Delete the above service using the admin API\r\n```\r\ncurl -X DELETE http://localhost:8001/services/test\r\n```\r\n4. The service gets deleted but responds with 500 Internal Server Error\r\n```\r\n{\"message\":\"An unexpected error occurred\"}\r\n```\r\n### Additional Details & Logs\r\n\r\n- Kong version (`0.14.1`)\r\n- Kong error logs\r\n```\r\n2018/10/25 18:45:04 [error] 41#0: *2062 lua coroutine: runtime error: .../share/lua/5.1/kong/db/strategies/cassandra/services.lua:35: attempt to get length of local 'entities' (a nil value)\r\nstack traceback:\r\ncoroutine 0:\r\n\t.../share/lua/5.1/kong/db/strategies/cassandra/services.lua: in function 'delete_cascade'\r\n\t.../share/lua/5.1/kong/db/strategies/cassandra/services.lua:64: in function 'delete_by_field'\r\n\t/usr/local/share/lua/5.1/kong/db/dao/init.lua:198: in function 'delete_entity'\r\n\t/usr/local/share/lua/5.1/kong/api/endpoints.lua:340: in function </usr/local/share/lua/5.1/kong/api/endpoints.lua:339>\r\ncoroutine 1:\r\n\t[C]: in function 'resume'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:393: in function 'handler'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:130: in function 'resolve'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:161: in function </usr/local/share/lua/5.1/lapis/application.lua:159>\r\n\t[C]: in function 'xpcall'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:159: in function 'dispatch'\r\n\t/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function 'serve_admin_api'\r\n\tcontent_by_lua(nginx-kong.conf:167):2: in function <content_by_lua(nginx-kong.conf:167):1>, client: 172.17.0.1, server: kong_admin, request: \"DELETE /services/test HTTP/1.1\", host: \"localhost:8001\"\r\n2018/10/25 18:45:04 [error] 41#0: *2062 [lua] init.lua:133: handle_error(): /usr/local/share/lua/5.1/lapis/application.lua:397: .../share/lua/5.1/kong/db/strategies/cassandra/services.lua:35: attempt to get length of local 'entities' (a nil value)\r\nstack traceback:\r\n\t.../share/lua/5.1/kong/db/strategies/cassandra/services.lua: in function 'delete_cascade'\r\n\t.../share/lua/5.1/kong/db/strategies/cassandra/services.lua:64: in function 'delete_by_field'\r\n\t/usr/local/share/lua/5.1/kong/db/dao/init.lua:198: in function 'delete_entity'\r\n\t/usr/local/share/lua/5.1/kong/api/endpoints.lua:340: in function </usr/local/share/lua/5.1/kong/api/endpoints.lua:339>\r\n\r\nstack traceback:\r\n\t[C]: in function 'error'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:397: in function 'handler'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:130: in function 'resolve'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:161: in function </usr/local/share/lua/5.1/lapis/application.lua:159>\r\n\t[C]: in function 'xpcall'\r\n\t/usr/local/share/lua/5.1/lapis/application.lua:159: in function 'dispatch'\r\n\t/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function 'serve_admin_api'\r\n\tcontent_by_lua(nginx-kong.conf:167):2: in function <content_by_lua(nginx-kong.conf:167):1>, client: 172.17.0.1, server: kong_admin, request: \"DELETE /services/test HTTP/1.1\", host: \"localhost:8001\"\r\n172.17.0.1 - - [25/Oct/2018:18:45:04 +0000] \"DELETE /services/test HTTP/1.1\" 500 43 \"-\" \"curl/7.54.0\"\r\n```\r\n- Operating system(`centos:7`)\r\n"}}
{"actor":{"display_login":"SravanYedhoti"}}