Actions
Refactor #16792
closedDon't modify AR record attributes in-place during normalisation
Description
Rails 5 now prefers to call #freeze on any string passed in as an attribute during validation, but this means attributes must not be edited in-place with gsub! and similar methods. Some of the pre-validation methods used to normalise hostnames, OS names etc will attempt to modify attributes in-place with gsub!, e.g.
HostsControllerTest::Fog.mock!#test_0001_#process_hostgroup changes compute attributes:
RuntimeError: can't modify frozen String
app/models/nic/interface.rb:101:in `gsub!'
app/models/nic/interface.rb:101:in `normalize_name'
app/models/concerns/orchestration.rb:77:in `valid?'
app/models/concerns/orchestration.rb:77:in `valid?'
app/models/concerns/foreman/sti.rb:29:in `save_with_type'
app/models/host.rb:15:in `method_missing'
test/functional/hosts_controller_test.rb:1271:in `initialize_host'
Prefer instead to retrieve and set the attribute through the regular attribute setter API (resource.foo = resource.foo.gsub(..)
).
https://github.com/rails/rails/issues/24185 and related tickets have more info.
Updated by The Foreman Bot about 8 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3915 added
Updated by Dominic Cleal almost 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 976bf6e0bdffa4a69fc76ee312060f815a6b7868.
Updated by Dominic Cleal almost 8 years ago
- Translation missing: en.field_release set to 209
Actions