{"action":"opened","issue":{"url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/2971","repository_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork","labels_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/2971/labels{/name}","comments_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/2971/comments","events_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/2971/events","html_url":"https://github.com/openfoodfoundation/openfoodnetwork/issues/2971","id":377393538,"node_id":"MDU6SXNzdWUzNzczOTM1Mzg=","number":2971,"title":"[Spree Upgrade] Soft-delete enterprisess","user":{"login":"sauloperez","id":762088,"node_id":"MDQ6VXNlcjc2MjA4OA==","avatar_url":"https://avatars1.githubusercontent.com/u/762088?v=4","gravatar_id":"","url":"https://api.github.com/users/sauloperez","html_url":"https://github.com/sauloperez","followers_url":"https://api.github.com/users/sauloperez/followers","following_url":"https://api.github.com/users/sauloperez/following{/other_user}","gists_url":"https://api.github.com/users/sauloperez/gists{/gist_id}","starred_url":"https://api.github.com/users/sauloperez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sauloperez/subscriptions","organizations_url":"https://api.github.com/users/sauloperez/orgs","repos_url":"https://api.github.com/users/sauloperez/repos","events_url":"https://api.github.com/users/sauloperez/events{/privacy}","received_events_url":"https://api.github.com/users/sauloperez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-05T13:11:07Z","updated_at":"2018-11-05T13:11:07Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Description\r\n\r\nSpree 2.0 made products soft-deletable in https://github.com/spree/spree/commit/3a9bbab32855e94484ae522b7f002867e1a5915b. That means that destroys now become updates. This is why the test below fails in `2-0-stable`\r\n\r\nhttps://github.com/openfoodfoundation/openfoodnetwork/blob/50a06d1bd9a88b35381b41e95a90a266a3640264/spec/models/enterprise_spec.rb#L36-L43\r\n\r\nNow the product doesn't get deleted from DB, then the enterprise does get deleted and that leaves the product orphan, which causes\r\n\r\n```shell\r\nPG::ForeignKeyViolation: ERROR:  update or delete on table \"enterprises\" violates foreign key constraint \"spree_products_supplier_id_fk\" on table \"spree_products\"\r\n       DETAIL:  Key (id)=(5) is still referenced from table \"spree_products\".\r\n       : DELETE FROM \"enterprises\" WHERE \"enterprises\".\"id\" = $1\r\n```\r\n\r\nThe solution here is to make enterprises soft-deletable as well by means of [paranoia](https://github.com/rubysherpas/paranoia).\r\n\r\n## Expected Behavior\r\n\r\nWhen deleting an enterprise, its supplied products should be marked as deleted as well as the enterprise itself. None of them will then be visible to users. This should make `spec/models/enterprise_spec.rb:36` pass.\r\n\r\n## Actual Behavior\r\n\r\n`spec/models/enterprise_spec.rb:36` fails as shown above.\r\n\r\n## Possible Fix\r\n\r\nWe need to add [paranoia](https://github.com/rubysherpas/paranoia) in our Gemfile and then run the migration to add the `deleted_at` column to the `enterprises` table. Then, enable it by calling `act_as_paranoid`.\r\n\r\nWe should watch for calls to `delete` as these will skip Paranoia's logic and thus get completely deleted from DB :warning: \r\n\r\n\r\n"}}
{"actor":{"display_login":"sauloperez"}}