Bug #24697
closedforeman-rake db:seed fails on upgrade to Foraman 1.17.1
Description
When upgrading our instance from 1.16.2 > 1.17.1, foreman_rake db:seed fails on 040-role.rb step with NoMethodError. I attached bookmarks, filters, roles, permissions from my database.
# foreman-rake db:seed --trace /opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Fixnum is deprecated /opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Bignum is deprecated /usr/share/foreman/lib/core_extensions.rb:183: warning: already initialized constant ActiveSupport::MessageEncryptor::DEFAULT_CIPHER /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/message_encryptor.rb:22: warning: previous definition of DEFAULT_CIPHER was here ** Invoke db:seed (first_time) ** Execute db:seed ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment The PGconn, PGresult, and PGError constants are deprecated, and will be removed as of version 1.0. You should use PG::Connection, PG::Result, and PG::Error instead, respectively. Called from /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require' ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:abort_if_pending_migrations Seeding /usr/share/foreman/db/seeds.d/020-partition_tables_list.rb Seeding /usr/share/foreman/db/seeds.d/020-permissions_list.rb Seeding /usr/share/foreman/db/seeds.d/020-provisioning_templates_list.rb Seeding /usr/share/foreman/db/seeds.d/020-roles_list.rb Seeding /usr/share/foreman/db/seeds.d/030-auth_sources.rb Seeding /usr/share/foreman/db/seeds.d/030-permissions.rb Seeding /usr/share/foreman/db/seeds.d/035-admin.rb Seeding /usr/share/foreman/db/seeds.d/040-roles.rb rake aborted! NoMethodError: undefined method `id' for nil:NilClass /usr/share/foreman/app/models/role.rb:324:in `block in find_current_filter' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/relation/delegation.rb:39:in `each' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/relation/delegation.rb:39:in `each' /usr/share/foreman/app/models/role.rb:324:in `detect' /usr/share/foreman/app/models/role.rb:324:in `find_current_filter' /usr/share/foreman/app/models/role.rb:320:in `filter_for_permissions_remove' /usr/share/foreman/app/models/role.rb:178:in `filters_and_filterings_for_removal' /usr/share/foreman/app/models/role.rb:173:in `block in find_for_permission_removal' /usr/share/foreman/app/models/role.rb:172:in `each' /usr/share/foreman/app/models/role.rb:172:in `inject' /usr/share/foreman/app/models/role.rb:172:in `find_for_permission_removal' /usr/share/foreman/app/models/role.rb:211:in `remove_permissions!' /usr/share/foreman/lib/seed_helper.rb:92:in `block in update_role_permissions' /usr/share/foreman/app/models/role.rb:234:in `ignore_locking' /usr/share/foreman/lib/seed_helper.rb:84:in `update_role_permissions' /usr/share/foreman/lib/seed_helper.rb:63:in `create_role' /usr/share/foreman/db/seeds.d/040-roles.rb:10:in `block (4 levels) in <top (required)>' /usr/share/foreman/db/seeds.d/040-roles.rb:9:in `each' /usr/share/foreman/db/seeds.d/040-roles.rb:9:in `block (3 levels) in <top (required)>' /usr/share/foreman/app/models/concerns/authorizable.rb:115:in `skip_permission_check' /usr/share/foreman/db/seeds.d/040-roles.rb:5:in `block (2 levels) in <top (required)>' /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.4.1/lib/audited/auditor.rb:283:in `without_auditing' /usr/share/foreman/db/seeds.d/040-roles.rb:4:in `block in <top (required)>' /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.4.1/lib/audited/auditor.rb:283:in `without_auditing' /usr/share/foreman/db/seeds.d/040-roles.rb:3:in `<top (required)>' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' /usr/share/foreman/db/seeds.rb:38:in `block (2 levels) in <top (required)>' /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:93:in `as' /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:99:in `as_anonymous_admin' /usr/share/foreman/db/seeds.rb:37:in `block in <top (required)>' /usr/share/foreman/db/seeds.rb:31:in `each' /usr/share/foreman/db/seeds.rb:31:in `<top (required)>' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/engine.rb:549:in `load_seed' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:270:in `load_seed' /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:184:in `block (2 levels) in <top (required)>' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' /opt/rh/rh-ruby24/root/usr/share/ruby/monitor.rb:214:in `mon_synchronize' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' /opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/exe/rake:27:in `<top (required)>' /opt/rh/rh-ruby24/root/usr/bin/rake:23:in `load' /opt/rh/rh-ruby24/root/usr/bin/rake:23:in `<main>' Tasks: TOP => db:seed
Removing role.rb shows it is the only one with an error:
# mv /usr/share/foreman/db/seeds.d/040-roles.rb . # foreman-rake db:seed /opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Fixnum is deprecated /opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Bignum is deprecated /usr/share/foreman/lib/core_extensions.rb:183: warning: already initialized constant ActiveSupport::MessageEncryptor::DEFAULT_CIPHER /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/message_encryptor.rb:22: warning: previous definition of DEFAULT_CIPHER was here The PGconn, PGresult, and PGError constants are deprecated, and will be removed as of version 1.0. You should use PG::Connection, PG::Result, and PG::Error instead, respectively. Called from /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require' Seeding /usr/share/foreman/db/seeds.d/020-partition_tables_list.rb Seeding /usr/share/foreman/db/seeds.d/020-permissions_list.rb Seeding /usr/share/foreman/db/seeds.d/020-provisioning_templates_list.rb Seeding /usr/share/foreman/db/seeds.d/020-roles_list.rb Seeding /usr/share/foreman/db/seeds.d/030-auth_sources.rb Seeding /usr/share/foreman/db/seeds.d/030-permissions.rb Seeding /usr/share/foreman/db/seeds.d/035-admin.rb Seeding /usr/share/foreman/db/seeds.d/050-taxonomies.rb Seeding /usr/share/foreman/db/seeds.d/060-architectures.rb Seeding /usr/share/foreman/db/seeds.d/070-provisioning_templates.rb Seeding /usr/share/foreman/db/seeds.d/080-partition_tables.rb Seeding /usr/share/foreman/db/seeds.d/100-installation_media.rb Seeding /usr/share/foreman/db/seeds.d/110-smart_proxy_features.rb Seeding /usr/share/foreman/db/seeds.d/130-compute_profiles.rb Seeding /usr/share/foreman/db/seeds.d/150-bookmarks.rb Seeding /usr/share/foreman/db/seeds.d/160-mail_notifications.rb Seeding /usr/share/foreman/db/seeds.d/170-notification_blueprints.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.11.2/db/seeds.d/20-foreman_tasks_permissions.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-11.0.0/db/seeds.d/50_discovery_templates.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.11.2/db/seeds.d/60-dynflow_proxy_feature.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-11.0.0/db/seeds.d/60_discovery_proxy_feature.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.11.2/db/seeds.d/61-foreman_tasks_bookmarks.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-11.0.0/db/seeds.d/70_discovery_mail_notification.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-11.0.0/db/seeds.d/80_discovery_ui_notification.rb Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-11.0.0/db/seeds.d/90_add_permissions_from_default_roles.rb All seed files executed
Files
Updated by Daniel Helgenberger over 6 years ago
- Subject changed from foreman-rake db:seed fails on upgrade to Foramen 1.17.1 to foreman-rake db:seed fails on upgrade to Foraman 1.17.1
Updated by Adam Winberg over 6 years ago
I had this error as well, both upgrading to 1.17 and then to 1.18. In my case it seems to be because I hade made edits to the filters in the 'Default role'. This role is not locked so I guess I presumed it was ok to make adjustments to it, but once I had reset the role to the default filters (view_bookmarks and view_tasks) the db:seed task worked.
Updated by Daniel Helgenberger over 6 years ago
Thanks, Adam! I'll try it right away - however, currently on 1.16.2 I cannot find a way to reset it. Can can you post you post your filters?
Updated by Adam Winberg over 6 years ago
As I understand it, from the file
/usr/share/foreman/db/seeds.d/020-roles_list.rb, there are only two filters/permissions on the default role:
Bookmark/view_bookmarks (Miscellaneous)/view_tasks
After I removed all my filters on the default role except those two, it worked for me.
Updated by Daniel Helgenberger over 6 years ago
Thanks, I think I also need from foreman tasks:
Foreman tasks/task view_foreman_tasks owner.id = current_user
Updated by Tomer Brisker over 6 years ago
- Priority changed from Normal to High
I confirm this issue is present in current nightly as well. Having a modified `default role` role will cause db:seed to fail.
Updated by Tomer Brisker over 6 years ago
More precisely:
- If there is a permission added to the default role with no filters, it will be removed when seeding.
- If there is a permission added with a specific filter, it will cause the db:seed task to fail.
Updated by Daniel Helgenberger over 6 years ago
Dumb question, should the Default Role be locked in the first place?
Adam and I only ran into the issue because it is unlocked and we assumed it is fine to edit it. Further, I edited this a while back, several forman versions ago and this is the first time I hit this.
Updated by Tomer Brisker about 6 years ago
- Related to Bug #21342: Role needs to be updated if their permissions changed in new version added
Updated by Tomer Brisker about 6 years ago
- Related to Feature #19039: Lock plugin roles added
Updated by The Foreman Bot about 6 years ago
- Status changed from New to Ready For Testing
- Assignee set to Tomer Brisker
- Pull request https://github.com/theforeman/foreman/pull/5992 added
Updated by Tomer Brisker about 6 years ago
- Target version set to 1.18.2
- Found in Releases 1.17.0, 1.17.0-RC1, 1.17.0-RC2, 1.17.1, 1.17.2, 1.17.3, 1.18.0, 1.18.0-RC1, 1.18.0-RC2, 1.18.0-RC3, 1.18.1, 1.19.0-RC1, 1.19.0-RC2, 1.19.0-RC3 added
Updated by The Foreman Bot about 6 years ago
- Pull request https://github.com/theforeman/foreman/pull/5999 added
Updated by The Foreman Bot about 6 years ago
- Pull request https://github.com/theforeman/foreman/pull/6000 added
Updated by The Foreman Bot about 6 years ago
- Pull request https://github.com/theforeman/foreman/pull/5990 added
Updated by Tomer Brisker about 6 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset ada7d6ef42de7a574bdf4e1f5998964fb4226368.
Updated by Tomer Brisker about 6 years ago
- Pull request deleted (
https://github.com/theforeman/foreman/pull/5990)
Updated by Tomer Brisker about 6 years ago
- Fixed in Releases 1.17.4, 1.18.2, 1.19.0, 1.20.0 added
Updated by Marek Hulán about 6 years ago
- Related to Bug #24231: foreman-rake db:seed error added