Bug #21770
closedGetting 'can't modify frozen String' error when publishing a content view that has lock conflict.
Description
Copied from BZ1517635.
Description of problem:
Getting the following error when publishing a content view that has lock conflict.
2017-11-01 00:15:49 [app] [I] Started POST "/katello/api/content_views/7/publish" for 10.240.44.251 at 2017-11-01 00:15:49 +0900
2017-11-01 00:15:49 [app] [I] Processing by Katello::Api::V2::ContentViewsController#publish as JSON
2017-11-01 00:15:49 [app] [I] Parameters: {"api_version"=>"v2", "id"=>"7", "content_view"=>{}}
2017-11-01 00:15:49 [app] [I] Authorized user admin(Admin User)
2017-11-01 00:15:50 [foreman-tasks/action] [E] can't modify frozen String (RuntimeError)
| /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.7.14.7/app/models/foreman_tasks/lock.rb:17:in `initialize'
| /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.7.14.7/app/models/foreman_tasks/lock.rb:49:in `new'
| /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.7.14.7/app/models/foreman_tasks/lock.rb:49:in `block in <class:Lock>'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:438:in `instance_exec'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:438:in `block in make_lambda'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:184:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:184:in `block in simple'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `run_callbacks'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activemodel-4.1.5/lib/active_model/validations.rb:377:in `run_validations!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activemodel-4.1.5/lib/active_model/validations/callbacks.rb:111:in `block in run_validations!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:113:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:113:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:166:in `block in halting'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `call'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `run_callbacks'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activemodel-4.1.5/lib/active_model/validations/callbacks.rb:111:in `run_validations!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activemodel-4.1.5/lib/active_model/validations.rb:318:in `valid?'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/validations.rb:70:in `valid?'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/validations.rb:77:in `perform_validations'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/validations.rb:57:in `save!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/transactions.rb:273:in `block in save!'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
| /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:199:in `transaction'
It appears that this issue only happen when for non-English users as the translated string becomes frozen (immutable) and caused the error.
Below is the prove:
Access 'foreman-rake console' and run:
- Default is English
I18n.locale
=> :en
msg = _("Required lock is already taken by other running tasks.")
=> "Required lock is already taken by other running tasks."
- Frozen return false for English
msg.frozen?
=> false
- Now change locale to Japanese
I18n.locale = :ja
=> :ja
msg = _("Required lock is already taken by other running tasks.")
=> "必要なロックはすでに他の実行中タスクにより取得されました"
- Frozen return true for Japanese
msg.frozen?
=> true
- Now change locale to Chinese
I18n.locale = 'zh-CN'
=> "zh-CN"
msg = _("Required lock is already taken by other running tasks.")
=> "所需锁定已被其他正在运行的任务使用。"
- Same issue as Japanese. It returns frozen string.
msg.frozen?
=> true
exit
Actual results:
Getting 'can't modify frozen String' error
Expected results:
The task should fail with "Required lock is already taken by other running tasks." message for specified language.
Updated by Adam Ruzicka over 6 years ago
Note:
We try to build up the error message by joining several frozen strings using #<< which modifies the receiver.
Updated by The Foreman Bot over 6 years ago
- Status changed from New to Ready For Testing
- Assignee set to Adam Ruzicka
- Pull request https://github.com/theforeman/foreman-tasks/pull/302 added
Updated by Anonymous over 6 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset f7c0a6ee4bbf9c8a4cb28b9876d0ff39f0a8fb09.