Skip to content

Resolve "Corrective Action: Added column to `members` table causes 500 errors to be returned in some cases"

What does this MR do and why?

This problem can happen when a new column is added to a table and we use UNION queries on that table, and the Rails app hasn't been restarted. One part of the query uses the underlying cached column list, while the other part uses the columns listed in the DB, leading to something like

PG::SyntaxError: ERROR:  each UNION query must have the same number of columns
LINE 5: (SELECT "members".* FROM "members" LEFT OUTER JOIN "users" O...

Add .select(*Member.cached_column_list) in order to ensure we're using the cached list of columns for both sides of the UNION query.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #350652 (closed)

Edited by Brett Walker

Merge request reports