Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Mysql2 -> Trilogy: ActiveRecord::ReadOnlyError replaced with ActiveRecord::StatementInvalid #72

@DaemonSpelledWrong

Description

@DaemonSpelledWrong

I recently swapped my company's database adapter over from mysql2 to trilogy and noticed that we were no longer rescuing ActiveRecord::ReadOnlyError exceptions because we started receiving ActiveRecord::StatementInvalid instead. Is it intended that Trilogy overwrites ActiveRecord::ReadOnlyError with ActiveRecord::StatementInvalid and, if so, may I ask why?

Further context:
My company uses Doorkeeper for Oauth2 in our Rails app. Doorkeeper utilizes oauth application credentials to create Doorkeeper::AccessToken objects with a token value users/APIs use when making requests to our own API. These token objects have a previous_refresh_token field that is "" by default and becomes populated with the previously used refresh token when you refresh your token.

On any given request, Doorkeeper will reset the previous_refresh_token column to "" if it is not currently "". So if you make a GET request with a token that was refreshed Doorkeeper will update the token and cause a write to the DB. This becomes a problem when all GET requests get routed to a reader connection. Previously we were capturing this case by rescuing ActiveRecord::ReadOnlyError but that changed and we were no longer handling these exceptions. I fixed it by additionally rescuing ActiveRecord::StatementInvalid but could've also fixed by simply executing all doorkeeper_token calls within a writer connection. However I am curious why this changed to begin with.

Edit: for more context, we're using Rails 6.1; not Rails 7+.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions