This Week in Rails

May 10, 2024

Rails community survey, improved association validation errors and more

Hi, Wojtek here. Let’s explore this week’s changes in the Rails.

The bi-annual Rails community survey is live!
Your input is invaluable and will help the team at Planet Argon gather insight on the current state of the Rails community. Fill in the survey here. (And feel free to share with your teams). The survey will remain open until August 2nd, 2024, and the findings released shortly thereafter.

A New Era for Ruby Central Events
Ruby Central announced that 2025 will be the last year of RailsConf and they are inviting the community to vote on where the last edition should be held. Read the full announcement here, and cast your vote.

Fix index_errors and provide :nested_attributes_order mode
This indexes the association validation errors based on the order received by nested attributes setter, and respects the reject_if configuration. This enables API to provide enough information to the frontend to map the validation errors back to their respective form fields.

Add flag to speed up multi-process test runs
Add ENV[“SKIP_TEST_DATABASE_TRUNCATE”] flag to speed up multi-process test runs on large databases, when all tests run within default transaction. This cuts ~10 seconds from the test run of HEY when run by 24 processes against the 178 tables, since ~4,000 table truncates can then be skipped.

Replace allocations count by GC time in request logs
Allocations count is often an interesting proxy for performance, but not necessarily the most relevant thing to include in request logs, given they aren’t a per thread metric, so the reporting is widely inaccurate in multi-threaded environments.

Since Ruby 3.1 there is now GC.total_time which is a monotonically increasing counter of time spent in GC. It still isn’t really a per thread metric, but it is more interesting because it uses the same unit as the response time, allowing to better see when you have a GC pause performance issue.

Explain that the default Dockerfile is intended for production
If people want to use Docker in development, they’d need a radically different setup, and are likely much better served by dev containers.

Don’t mess with Minitest unless RAILS_ENV is set
Minitest will automatically scan all installed gems and load plugins from those gems. We should detect whether or not we’re being run within the context of a Rails app and only change MT behavior in that case.

Warn about changing “query_constraints” behavior
Add a deprecation warning for the query_constraints: association option. This option will change behavior in the future versions of Rails and applications are encouraged to switch to foreign_key: to preserve the current behavior.

Consistently use desired test adapter in Active Job
All tests now respect the active_job.queue_adapter config, which previously was not always the case.

You can view the whole list of changes here. We had 20 contributors to the Rails codebase this past week!

Until next time!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.