fix: detect chart SQL dialect from queue connection#43
Merged
Conversation
The activity chart's time-bucketing query picked its SQL dialect from ActiveRecord::Base.connection, the host app's primary database. On multi-database setups where Solid Queue runs on a different engine (e.g. MySQL primary + dedicated PostgreSQL queue via config.solid_queue.connects_to), this built MySQL UNIX_TIMESTAMP() SQL and ran it against Postgres, raising PG::UndefinedFunction and 500ing the whole dashboard since show_chart defaults to true. Detect the adapter from the Solid Queue model's own connection instead. Single-database and same-engine setups emit byte-identical SQL. Fixes #42
This was referenced Jul 13, 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
ActiveRecord::Base.Problem
On a multi-database app with a MySQL primary and a dedicated PostgreSQL queue database (
config.solid_queue.connects_to = { database: { writing: :queue } }), the chart's time-bucketing query raised:ChartDataService#adapter?picked the SQL dialect fromActiveRecord::Base.connection— the primary (MySQL) database — so it emitted MySQLUNIX_TIMESTAMP()SQL and then executed it against the Postgres queue database. Becauseshow_chartdefaults totrueand the chart data is computed inline inOverviewController#indexwith no rescue, this took down the entire dashboard page for affected users, not just the chart.Fixes #42.
Solution
Detect the adapter from the model's own connection (
SolidQueue::Job.connection), which is the connection the query actually runs on. Themodelis threaded throughbucket_index_exprintoadapter?.For single-database apps and same-engine multi-database apps,
SolidQueue::Job.connectionresolves to the same adapter asActiveRecord::Base.connection, so the generated SQL is byte-identical — no behavioral change. Only the previously-crashing mixed-engine path changes.Changes
app/services/solid_queue_monitor/chart_data_service.rb:adapter?(model, name)readsmodel.connection.adapter_name;bucket_index_exprtakes the model.spec/services/solid_queue_monitor/chart_data_service_spec.rb: new adapter-detection specs per engine (Postgres / MySQL / Trilogy / SQLite) plus a regression case reproducing config.show_chart = true fails with postgres #42 (MySQL primary + Postgres queue model → assertsEXTRACT(EPOCH ...), neverUNIX_TIMESTAMP).CHANGELOG.md:[Unreleased] → Fixedentry.Testing
346 examples, 0 failuresbundle exec rubocopclean on changed filesspec/requests/solid_queue_monitor/csp_compatibility_spec.rbpassesBackward compatibility
Fully backward compatible. Safe to ship as a patch release (2.2.1) — no config, no migration.
Checklist