Skip to content

ActionCable Postgres adapter is ActiveRecord-specific #27214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bgentry opened this issue Nov 29, 2016 · 10 comments
Open

ActionCable Postgres adapter is ActiveRecord-specific #27214

bgentry opened this issue Nov 29, 2016 · 10 comments

Comments

@bgentry
Copy link
Contributor

bgentry commented Nov 29, 2016

Steps to reproduce

  1. Create a Rails app using Sequel and sequel-rails, without ActiveRecord
  2. Attempt to use the ActionCable Postgres adapter
  3. Watch it crash trying to autoload ActiveRecord

Expected behavior

Ideally, this would support the most popular Postgres ORMs out of the box. Or at least the docs should mention that this only works with AR.

Actual behavior

Exception trying to autoload ActiveRecord

System configuration

Rails version: 5.0.0.1

Ruby version: 2.3.3

It was very easy to fork the Postgres ActionCable subscription adapter to work with Sequel. I only had to alter the with_connection method, which is even shorter with Sequel: https://gist.github.com/bgentry/5a4592dbbcc398c0ad651c53af7da51f#file-postgresql_sequel-rb-L35-L40

I'm not sure whether the right approach is to try to support this out-of-the-box, or at least to document that the adapter is AR-specific. Thoughts?

As a user I'd certainly prefer not to have to maintain a fork of the subscription adapter. But I can certainly see the argument for this not being Rails' problem. I suppose I really only need to monkey-patch or refine that one method, though, so not too bad either way.

@rafaelfranca
Copy link
Member

That is a good point. I don't see why this code is using Active Record at all, it should not, even more that actioncable doesn't depend on activerecord and active record base is not being required in that file.

In my opinion we should use the pg connection directly.

@bgentry
Copy link
Contributor Author

bgentry commented Nov 29, 2016

@rafaelfranca my guess is it's because it's piggybacking on the AR database config logic. An alternative approach to supporting any ORM is to have a config setting that lets me specify how to get a new PG connection, defaulting to the AR method used currently.

I did notice the lack of a require at the top which is maybe a separate but related issue?

@rafaelfranca
Copy link
Member

I prefer to use the connection directly over supporting different ORM. There is no need for a ORM in actioncable.

We can't add the require without changing the dependencies of actioncable to add activerecord, so I prefer that we solve this issue removing any orm specific code.

@maclover7
Copy link
Contributor

Thank you for opening up this issue! Working on a solution locally now.

@maclover7 maclover7 self-assigned this Nov 29, 2016
@maclover7
Copy link
Contributor

Opened up #27216 as a possible solution for this.

@KarimElsayad247
Copy link

This issue remains open after... 6 years! RailsGuides still mention this behavior might be changed

@reiz
Copy link

reiz commented Jun 10, 2023

I would like to use it together with MongoID. I have already a MongoDB cluster on production and I would like to avoid adding Redis, because of different reasons.

@dbackeus
Copy link

dbackeus commented Nov 2, 2023

I've released a rubygem which enhances the Postgres adapter, making it possible to bypass the ActiveRecord dependency by adding explicit url configuration. It also fixes the 8000 byte payload size limit.

Rubygem: https://rubygems.org/gems/actioncable-enhanced-postgresql-adapter
Documentation: https://github.com/reclaim-the-stack/actioncable-enhanced-postgresql-adapter#readme

@washu
Copy link

washu commented Mar 21, 2024

I written one that uses mongoid.
I have a not tested yet mongoid, subscription adapter. but can you send you a gist

@washu
Copy link

washu commented Mar 21, 2024

https://gist.github.com/washu/a2b5415e7b9a538fe782d32ff5bb9109

I just wrapped some code i had in my own crystal/anycable type bridge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants