Skip to content
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

Remove connected? check from db_runtime payload #48708

Merged

Conversation

eileencodes
Copy link
Member

The check for Base.connected? was added in
4ecdf24. At the time this change was made, we were calling
Base.connection.reset_runtime so it made sense to check if the database was connected. Since
dd61a81 we have stored that information in a thread instead, negating the need to check Base.connected?.

The problem with checking Base.connected? is that in a multi-db application this will return false for any model running a query not inheriting from Base, leaving the db_runtime payload nil. Since the information we need is stored in a thread rather than on the connection directly we can remove the Base.connected? check.

Fixes #48687

The check for `Base.connected?` was added in
rails@4ecdf24.
At the time this change was made, we were calling
`Base.connection.reset_runtime` so it made sense to check if the
database was connected. Since
rails@dd61a81
we have stored that information in a thread instead, negating the need
to check `Base.connected?`.

The problem with checking `Base.connected?` is that in a multi-db
application this will return `false` for any model running a query not
inheriting from `Base`, leaving the `db_runtime` payload `nil`. Since
the information we need is stored in a thread rather than on the
connection directly we can remove the `Base.connected?` check.

Fixes rails#48687
@eileencodes eileencodes merged commit 8cc23bf into rails:main Jul 10, 2023
9 checks passed
@eileencodes eileencodes deleted the remove-connected-check-from-db_runtime branch July 10, 2023 15:44
@eileencodes
Copy link
Member Author

Backported to 7-0-stable in eaf6dcf

eileencodes added a commit that referenced this pull request Jul 11, 2023
…m-db_runtime

Remove connected? check from db_runtime payload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveRecord time not included in request logs when shard_resolver is used
1 participant