misc: avoid ActiveRecord::PreparedStatementCacheExpired errors #3645
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.
Context
In some context, when a migration is adding a new column to a table, Postgres might return a
cached plan must not change result type
in a transaction because the cached query plan is not more valid. This error is then raised as aActiveRecord::PreparedStatementCacheExpired
by RailsSee https://flexport.engineering/avoiding-activerecord-preparedstatementcacheexpired-errors-4499a4f961cf
Description
This fix is forcing rails to query explicitly every columns in select instead of using
SELECT *
, so that the cached plan remains valid in the transaction. The only drawback will be with column removal, but it should never happen on a used field and would be prevented bystrong_migrations