Mobility Rails 8.0 Compatibility Issue - GitHub Issue Template
Environment
- Mobility version: 1.3.2
- Rails version: 8.0.3
- Ruby version: 3.3.3
- Database: PostgreSQL
Description
The Rails 8.0 compatibility fix introduced in Mobility 1.3.2 (referencing PR #654 and #655) contains an incomplete implementation that causes a NoMethodError when select_values contains plain strings instead of Arel nodes.
Error
NoMethodError: undefined method `right' for an instance of String
Root Cause
The select_for_count method in lib/mobility/plugins/active_record/query.rb assumes all values in select_values respond to .right and .left methods (i.e., are Arel::Nodes::As objects):
if select_values.any? { |value| value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) }
filtered_select_values = select_values.map do |value|
value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) ? value.left : value
end
# ...
end
However, as noted in PR #654's comments, Rails 8.0 changed behavior (commit: rails/rails@ba468db) such that select_values can contain plain strings like "id" instead of Arel nodes.
Steps to Reproduce
- Upgrade to Rails 8.0.x
- Use Mobility 1.3.2
- Perform any query that triggers
select_for_count with a simple select value
- Observe the
NoMethodError on .right
Proposed Fix
Check if values respond to .right before calling it:
Mobility Rails 8.0 Compatibility Issue - GitHub Issue Template
Environment
Description
The Rails 8.0 compatibility fix introduced in Mobility 1.3.2 (referencing PR #654 and #655) contains an incomplete implementation that causes a
NoMethodErrorwhenselect_valuescontains plain strings instead of Arel nodes.Error
Root Cause
The
select_for_countmethod inlib/mobility/plugins/active_record/query.rbassumes all values inselect_valuesrespond to.rightand.leftmethods (i.e., areArel::Nodes::Asobjects):However, as noted in PR #654's comments, Rails 8.0 changed behavior (commit: rails/rails@ba468db) such that
select_valuescan contain plain strings like"id"instead of Arel nodes.Steps to Reproduce
select_for_countwith a simple select valueNoMethodErroron.rightProposed Fix
Check if values respond to
.rightbefore calling it: