{"action":"created","issue":{"url":"https://api.github.com/repos/slick/slick/issues/1197","labels_url":"https://api.github.com/repos/slick/slick/issues/1197/labels{/name}","comments_url":"https://api.github.com/repos/slick/slick/issues/1197/comments","events_url":"https://api.github.com/repos/slick/slick/issues/1197/events","html_url":"https://github.com/slick/slick/issues/1197","id":94358507,"number":1197,"title":"Slick 3.0 withTransaction blocks are required to interact with libraries","user":{"login":"Ciantic","id":64731,"avatar_url":"https://avatars.githubusercontent.com/u/64731?v=3","gravatar_id":"","url":"https://api.github.com/users/Ciantic","html_url":"https://github.com/Ciantic","followers_url":"https://api.github.com/users/Ciantic/followers","following_url":"https://api.github.com/users/Ciantic/following{/other_user}","gists_url":"https://api.github.com/users/Ciantic/gists{/gist_id}","starred_url":"https://api.github.com/users/Ciantic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ciantic/subscriptions","organizations_url":"https://api.github.com/users/Ciantic/orgs","repos_url":"https://api.github.com/users/Ciantic/repos","events_url":"https://api.github.com/users/Ciantic/events{/privacy}","received_events_url":"https://api.github.com/users/Ciantic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-07-10T17:55:17Z","updated_at":"2015-08-13T22:22:06Z","closed_at":null,"body":"There are at least two #1148 and #1093 that looks like a duplicate, but according to discussion at Slack with @cvogt I decided to open this anyway.\r\n\r\nSuppose there is a *external library* which has trait e.g.\r\n\r\n```\r\ntrait CatDao {\r\n  def save(input: Cat): Future[Cat]\r\n}\r\ntrait DogDao {\r\n  def save(input: Dog): Future[Dog]\r\n}\r\n```\r\n\r\nIf I then create implementation using slick for A, and B, they look something like this:\r\n\r\n```\r\nclass DbCatDao extends CatDao {\r\n  def save(input: Cat): Future[Cat] = {\r\n    db.run(((Table returning Table.map(_.id) into ((u, insertId) => input.copy(id=insertId))) += input))\r\n  }\r\n}\r\n\r\nclass DbDogDao extends DogDao {\r\n  def save(input: Dog): Future[Dog] = {\r\n    db.run(((Table returning Table.map(_.id) into ((u, insertId) => input.copy(id=insertId))) += input))\r\n  }\r\n}\r\n```\r\n\r\nNow somewhere in code you may need to call them both in one transaction, it was possible with `db.withTransaction` before, now it is not possible at all because it was deprecated.\r\n\r\n```\r\ndb.withTransaction {\r\n  for {\r\n    cat <- dbCatDao.save(...)\r\n    dog <- dbDogDao.save(...) \r\n  }\r\n}\r\n```\r\n\r\nWith having only `transactionally` available, there is no good way to fix this, because they don't return `DBIOAction`, and I can't change their return types because they are meant to implement the contract in given in external library.\r\n\r\nI understand that `transactionally` is better when one controls the libraries, but it's not suitable when interacting with external libraries always.\r\n\r\n**I'll add** Example above is extremely simple, and finding a workaround in this case may be possible, but it gets trickier when trait requires you to implement tens of `Future[Something]` methods."},"comment":{"url":"https://api.github.com/repos/slick/slick/issues/comments/130865250","html_url":"https://github.com/slick/slick/issues/1197#issuecomment-130865250","issue_url":"https://api.github.com/repos/slick/slick/issues/1197","id":130865250,"user":{"login":"asazernik","id":1307640,"avatar_url":"https://avatars.githubusercontent.com/u/1307640?v=3","gravatar_id":"","url":"https://api.github.com/users/asazernik","html_url":"https://github.com/asazernik","followers_url":"https://api.github.com/users/asazernik/followers","following_url":"https://api.github.com/users/asazernik/following{/other_user}","gists_url":"https://api.github.com/users/asazernik/gists{/gist_id}","starred_url":"https://api.github.com/users/asazernik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asazernik/subscriptions","organizations_url":"https://api.github.com/users/asazernik/orgs","repos_url":"https://api.github.com/users/asazernik/repos","events_url":"https://api.github.com/users/asazernik/events{/privacy}","received_events_url":"https://api.github.com/users/asazernik/received_events","type":"User","site_admin":false},"created_at":"2015-08-13T22:22:06Z","updated_at":"2015-08-13T22:22:06Z","body":"They [are not executed in a single DB access](http://slick.typesafe.com/doc/3.0.0/dbio.html#transactions-and-pinned-sessions):\r\n\r\n> When executing a DBIOAction which is composed of several smaller actions, Slick acquires sessions from the connection pool and releases them again as needed so that a session is not kept in use unnecessarily while waiting for the result from a non-database computation (e.g. the function passed to flatMap that determines the next Action to run). "}}