Project

General

Profile

Actions

Refactor #16792

closed

Don't modify AR record attributes in-place during normalisation

Added by Dominic Cleal over 7 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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.

Actions #1

Updated by The Foreman Bot over 7 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3915 added
Actions #2

Updated by Dominic Cleal over 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #3

Updated by Dominic Cleal over 7 years ago

  • translation missing: en.field_release set to 209
Actions

Also available in: Atom PDF