Fix tracked column writes on Rails main #24
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 612 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.384
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #24"
general
weight: 0.35
grosser
We're now overriding
define_method_attribute=, which is a method defined inRails to generate setter methods for models' columns. If we want to track
changes to a column, we need the setter to call
_write_attribute, as it usedto, because that's the method DeltaChanges overrides to track changes.
Otherwise, Rails' default generated setter will call
@attributes.write_from_userdirectly, thus bypassing our override/"hook" into_write_attribute. Our setter still ends up calling@attributes.write_from_user, but it gets there through_write_attribute,which allows DeltaChanges to record the change.
By overriding
define_method_attribute=, we can generate the setter we need,but we only want to do this on Rails versions which no longer generate setters
that call
_write_attribute, and only for columns DeltaChanges has beenconfigured to track. Currently, that's Rails main, which our version check
includes using
>= 8.2.a. If we're on an older version of Rails which alreadygenerates setters that call
_write_attribute, our DeltaChanges "hook" alreadyworks, so we can skip defining our generator override entirely. On newer Rails,
if DeltaChanges hasn't been configured to track a particular column, we can
call
superto allow Rails' default setter generator to handle that column.There's also the case where Rails has already generated setter methods before
DeltaChanges is configured. Setting the configuration won't change those
existing methods on its own. On these newer Rails versions, calling
delta_changeswith a nonempty:columnslist also callsundefine_attribute_methods. This removes the generated attribute methods andresets Rails' "attribute methods generated" flag. The next time Rails calls
define_attribute_methods, for example when initializing a record, our generatoroverride uses the newly configured options to decide which setters should call
_write_attributeand which can be generated by Rails when our override callssuper.Ref: https://github.com/rails/rails/commit/0f6c0a05e2064b56f759677d94f060f057d89c66
Something worth mentioning, by routing through
_write_attribute, we're essentially undoing the benefits introduced by doing direct writes instead. However, benchmarks (adapted from https://github.com/rails/rails/pull/59191) show there is no performance regression of DeltaChanges between Rails 8.1 and Rails 8.2+. _When benchmarking between tracked and untracked columns in Rails 8.2+ (not shown), we do see DeltaChanges' overhead increase._<details><summary>Benchmark</summary>
<p>
</p>
</details>