Fix AmbiguousColumn error in Orderable concern
What does this MR do and why?
Fixes AmbiguousColumn error in the Orderable concern when used with models that have separate verification state tables.
Changes made:
-
Refactor
Orderableconcern: Updatedorder_by_primary_keyscope to usearel_table[primary_key]instead of justprimary_keyto avoid SQL ambiguity when joining tables with the same column names -
Clean up
PackagesNugetSymbolStatemodel: Removed unnecessaryself.primary_key = :packages_nuget_symbol_idassignment. It was a copy-past leftover, which isn't correct since the PK of the table is theidcolumn. - Enhance test factories: Improved NuGet symbol factory traits to properly set up verification states and associations for testing
- Add unit tests: Added test coverage for data management API with models that use separate verification state tables
Why this change is needed:
The AmbiguousColumn error occurs when ActiveRecord queries involve joins between tables that have columns with the same name (like id). By using arel_table[primary_key], we explicitly specify which table's primary key column to use, eliminating the ambiguity. This is particularly important for Geo replication features where verification state tables are joined with their parent models.
References
Screenshots or screen recordings
N/A
How to set up and validate locally
-
Set up a local Geo environment with a primary and secondary node. Follow the Geo development setup guide.
-
Hit the
data_managementAPI:
curl -H "Authorization: Bearer <token>" "http://localhost:3000/api/v4/admin/data_management/packages_nuget_symbol?checksum_state=succeeded"
It should return an empty array, which means no errors. On master, it will result in a 500 with this error in the logs: ActiveRecord::StatementInvalid (PG::AmbiguousColumn: ERROR: column reference "id" is ambiguous
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #578343 (closed)