Repository navigation
fix: let Action Cable's PostgreSQL subscription adapter run on aws_po… - #197
Merged
Merged
Conversation
…stgresql Action Cable's PostgreSQL subscription adapter refuses any raw connection that is not a PG::Connection, and aws_postgresql hands out a WrapperPgConnection, so every subscribe and broadcast (including Turbo Stream broadcasts) raised "The Active Record database must be PostgreSQL in order to use the PostgreSQL Action Cable storage adapter". The aws_postgresql adapter now registers an :action_cable load hook that prepends a verify! override to ActionCable::SubscriptionAdapter::PostgreSQL, accepting a WrapperPgConnection and leaving every other connection to Action Cable's own check. The calls Action Cable makes on the connection (exec, escape_identifier, escape_string, wait_for_notify) are forwarded to the wrapped PG::Connection.
sophia-bq
approved these changes
Oct 6, 2026
JuanLeee
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix Action Cable's PostgreSQL subscription adapter (
adapter: postgresqlincable.yml) refusing to run on theaws_postgresqlActiveRecord adapter.Description
Stacked on #196 (which is stacked on #195) - review and merge those first; this PR's diff is the single commit on top of them.
Action Cable's PostgreSQL subscription adapter checks that the raw connection it gets from ActiveRecord is a
PG::Connection, and raises otherwise.aws_postgresqlhands out aWrapperPgConnection, so every subscribe and broadcast failed withThe Active Record database must be PostgreSQL in order to use the PostgreSQL Action Cable storage adapter. Turbo Stream broadcasts (broadcasts_to,broadcast_replace_to) go through the same path and failed too. The stockpostgresqladapter works.Changes:
ActiveRecord::ConnectionAdapters::AwsActionCablePostgreSQLSupport, loaded by theaws_postgresqladapter. It registers anActiveSupport.on_load(:action_cable)hook that loads Action Cable's PostgreSQL subscription adapter and prepends averify!override. The override accepts aWrapperPgConnectionand passes every other connection to Action Cable's own check.exec,escape_identifier,escape_string,wait_for_notify) are already forwarded to the wrappedPG::Connection.WrapperPgConnection#is_a?is unchanged, so code that needs a realPG::Connectionis not misled.Testing:
spec/unit/aws_action_cable_postgresql_support_spec.rb, using a stand-in for Action Cable's adapter inspec/fixtures/action_cable_stub(Action Cable is not a dependency of the gem). It fails without the fix and checks that non-PostgreSQL connections are still rejected.bundle exec rspec spec/unit: 3138 examples, 0 failures. The new spec also passes under ActiveRecord 7.2 and 8.0.bundle exec rubocop lib spec: no offenses.aws_postgresql: a subscribe followed by a broadcast delivers the message, with Action Cable loaded both before and after the adapter. Before the fix the same test failed with the error above; the stockpostgresqladapter passed.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.