Repository navigation
Conversation
Since ActiveRecord 7.2, `Model.connection` performs an implicit permanent checkout. Applications that set `ActiveRecord.permanent_connection_checkout` to `:deprecated` get a deprecation warning (an exception when deprecations raise), and `:disallowed` always raises. Diagram generation then aborted in `Attribute#native_type`, and the tbls generator silently emitted no indexes because its `rescue StandardError` swallowed the error. Use `Model.connection_pool.with_connection` instead. It exists on every supported ActiveRecord version, so no version branching is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Graphviz generation fails and tbls omits indexes with restricted permanent connection checkout
Thank you for maintaining
rails-erd.I encountered a connection checkout compatibility issue while generating diagrams with ActiveRecord 7.2.4 and have prepared a small fix with regression tests.
Problem
With
ActiveRecord.permanent_connection_checkout = :disallowed, Graphviz PDF generation raisesActiveRecord::ActiveRecordErrorinRailsERD::Domain::Attribute#native_type.The tbls generator encounters the same restriction while reading indexes. Its existing
rescue StandardErrorreturns an empty array, causing index metadata to be silently omitted.The issue also occurs with
:deprecatedwhenActiveRecord.deprecator.behavior = :raise.An existing connection lease can mask the problem, so reproduction requires running the affected operations without a previously leased connection.
Root cause
Both
Attribute#native_typeandDiagram::Tbls#indexes_payloadcallModel.connection, which may perform an implicit permanent connection checkout.ActiveRecord 7.2 introduced configuration to deprecate or disallow this behavior.
Proposed fix
Use
model.connection_pool.with_connectionat the two metadata access sites.This scopes connection usage to the operation and avoids version-specific branches. The pool API is also available in ActiveRecord 7.0.
Verification
I reproduced the problem using independent SQLite processes on ActiveRecord 7.2.4, testing all six combinations of:
true,:deprecated,:disallowed:raise, logging collectorBefore the fix:
:deprecatedwith:raiseprevented Graphviz generation and caused tbls indexes to be omitted.:disallowedconfigurations produced the same failures.:deprecatedwith logging allowed generation but emitted a deprecation warning.After the fix, Graphviz generated PDFs with valid signatures and tbls preserved the unique index in all six configurations, without connection deprecation warnings.
Three regression tests also confirmed the original failure: one assertion failure and two errors without the fix on ActiveRecord 7.2.4.
The repaired implementation passes the full test suite on the locally tested ActiveRecord versions.
References
Would you be open to a pull request for this approach? I'm happy to adapt the implementation or tests to the project's conventions.