# 업그레이드 실패 (NoMethodError: Bookmark:Class에 대한 'register\_bookmarkable' 메서드 정의되지 않음)

**URL:** https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761
**Category:** Self-hosting
**Created:** [3월 20, 2023, 3:51오후 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761 "2023-03-20T15:51:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)
#### Post date: [3월 20, 2023, 3:51오후 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761/1 "2023-03-20T15:51:38Z")

</div>

관리자 웹 인터페이스에서 3.1.0.beta2에서 beta3로 업그레이드를 수행하던 중, Docker Manager 업그레이드는 성공적으로 완료된 것으로 생각되지만, 이후 메인 Discourse 업그레이드가 다음과 같이 실패했습니다:

```plaintext
$ yarn install --production
yarn install v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning " > @mixer/parallel-prettier@2.0.3" has unmet peer dependency "prettier@^2.0.0".
warning "eslint-config-discourse > eslint-plugin-lodash@7.1.0" has unmet peer dependency "lodash@>=4".
[5/5] Building fresh packages...
$ yarn --cwd app/assets/javascripts/discourse $(node -e 'if(JSON.parse(process.env.npm_config_argv).original.includes(`--frozen-lockfile`)){console.log(`--frozen-lockfile`)}')
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > babel-plugin-debug-macros@0.4.0-pre1" has unmet peer dependency "@babel/core@^7.0.0".
warning "workspace-aggregator-0156df5c-af27-46bf-a6aa-a0a12748bb32 > discourse > @uppy/xhr-upload@3.1.0" has incorrect peer dependency "@uppy/core@^3.0.6".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 20.00s.
Done in 44.16s.
$ LOAD_PLUGINS=0 bundle exec rake plugin:pull_compatible_all
discourse-data-explorer is already at latest compatible version
docker_manager is already at latest compatible version
$ SKIP_POST_DEPLOYMENT_MIGRATIONS=1 bundle exec rake multisite:migrate
rake aborted!
NoMethodError: undefined method `register_bookmarkable' for Bookmark:Class
Did you mean? registered_bookmarkables
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.3/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/var/www/discourse/plugins/discourse-data-explorer/plugin.rb:902:in `block in activate!'
/var/www/discourse/lib/plugin/instance.rb:503:in `block in notify_after_initialize'
/var/www/discourse/lib/plugin/instance.rb:501:in `each'
/var/www/discourse/lib/plugin/instance.rb:501:in `notify_after_initialize'
/var/www/discourse/config/application.rb:228:in `each'
/var/www/discourse/config/application.rb:228:in `block (2 levels) in <class:Application>'
/var/www/discourse/lib/plugin.rb:6:in `initialization_guard'
/var/www/discourse/config/application.rb:228:in `block in <class:Application>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:92:in `block in execute_hook'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:85:in `with_execution_control'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:90:in `execute_hook'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:76:in `block in run_load_hooks'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:75:in `each'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/lazy_load_hooks.rb:75:in `run_load_hooks'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/application/finisher.rb:87:in `block in <module:Finisher>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
/var/www/discourse/config/environment.rb:7:in `<main>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/application.rb:348:in `require_environment!'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.3/lib/rails/application.rb:511:in `block in run_tasks_blocks'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:58:in `load'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:58:in `kernel_load'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:23:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:491:in `exec'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:34:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:28:in `start'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/exe/bundle:45:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bundler-2.4.4/exe/bundle:33:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/bin/bundle:25:in `load'
/var/www/discourse/vendor/bundle/ruby/3.1.0/bin/bundle:25:in `<main>'
Tasks: TOP => multisite:migrate => db:load_config => environment
(See full trace by running task with --trace)
Docker Manager: FAILED TO UPGRADE
#<RuntimeError: RuntimeError>
/var/www/discourse/plugins/docker_manager/lib/docker_manager/upgrader.rb:202:in `run'
/var/www/discourse/plugins/docker_manager/lib/docker_manager/upgrader.rb:101:in `upgrade'
/var/www/discourse/plugins/docker_manager/scripts/docker_manager_upgrade.rb:19:in `block in <main>'
/var/www/discourse/plugins/docker_manager/scripts/docker_manager_upgrade.rb:6:in `fork'
/var/www/discourse/plugins/docker_manager/scripts/docker_manager_upgrade.rb:6:in `<main>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.1/lib/rails/commands/runner/runner_command.rb:43:in `load'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.1/lib/rails/commands/runner/runner_command.rb:43:in `perform'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.1/lib/rails/command/base.rb:87:in `perform'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.1/lib/rails/command.rb:48:in `invoke'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4.1/lib/rails/commands.rb:18:in `<main>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
bin/rails:18:in `<main>'
Spinning up 1 Unicorn worker(s) that were stopped initially

```

포럼은 실행 중이지만, 현재 상태가 명확하지 않습니다(제 기준으로는). 업그레이드 페이지에서는 최신 릴리스 +24 버전이며, docker\_manager는 e90c8f55 버전으로 최신이고, 업그레이드가 필요한 유일한 구성 요소가 [Data Explorer](https://meta.discourse.org/t/32566?silent=true)라고 표시합니다. 하지만 대시보드에서는 여전히 beta2 (b96869d5fb) 버전이라고 표시되고 있습니다.

어떻게 해야 할까요? 제 추측으로는 CLI를 통해 업그레이드를 수행하는 것이 최선인 것 같습니다. 현재 포럼을 읽기 전용 모드로 설정해 두었습니다.

---

<div class="post-metadata">

### Author: ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)
#### Post date: [3월 20, 2023, 6:15오후 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761/2 "2023-03-20T18:15:21Z")

</div>

최근 코드에서 원인으로 의심되는 몇 가지 변경 사항을 찾았고, 이제 더 이상 최신 상태가 아닌 **discourse-data-explorer 플러그인** 과의 충돌로 보입니다.

그래서 지금은 해당 플러그인 없이도 작동할 수 있으므로 **app.yml에서 해당 줄을 제거** 하고 재빌드했습니다. (그냥 있는 그대로 재빌드해볼 수도 있었지만, 이미 몇 시간 동안 오프라인 상태였습니다.) 그 결과 **성공적으로** 다시 실행되고 있습니다.

(제 조치는 수정이 아닌 임시 해결책이라고 생각합니다.)

관련이 있을 수 있는 변경 사항은 다음과 같습니다.

> <https://github.com/discourse/discourse/commit/184ce647ea7e9159b43b3552f334e6508e6aef51>
>
> Prior to this change \`registered\_bookmarkable\` would return \`nil\` as \`type\` in …\`Bookmark.registered\_bookmarkable\_from\_type(type)\` would be \`ChatMessage\` and we registered a \`Chat::Message\` class.
> 
> This commit will now properly rely on each model \`polymorphic\_class\_for(name)\` to help us infer the proper type from a a \`bookmarkable\_type\`.
> 
> Tests have also been added to ensure that creating/destroying chat message bookmarks is working correctly.
> 
> \---
> 
> Longer explanation
> 
> Currently when you save a bookmark in the database, it's associated to another object through a polymorphic relationship, which will is represented by two columns: \`bookmarkable\_id\` and \`bookmarkable\_type\`. The \`bookmarkable\_id\` contains the id of the relationship (a post ID for example) and the \`bookmarkable\_type\` contains the type of the object as a string by default, (\`"Post"\` for example).
> 
> Chat plugin just started namespacing objects, as a result a model named \`ChatMessage\` is now named \`Chat::Message\`, to avoid complex and risky migrations we rely on methods provided by rails to alter the \`bookmarkable\_type\` when we save it: we want to still save it as \`"ChatMessage"\` and not \`"Chat::Message"\`. And, to retrieve the correct model when we load the bookmark from the database: we want \`"ChatMessage"\` to load the \`Chat::Message\` model and not the \`ChatMessage\`model which doesn't exist anymore.
> 
> On top of this the bookmark codepath is allowing plugins to register types and will check against these types, so we alter this code path to be able to do a similar ChatMessage \<-\> Chat::Message dance and allow to check the type is valid. In the specific case of this commit, we were retrieving a \`"ChatMessage"\` bookmarkable\_type from the DB and looking for it in the registered bookmarkable types which contain \`Chat::Message\` and not \`ChatMessage\`.

> <https://github.com/discourse/discourse/commit/360d0dde650704a0f01fd6d8b525e933b1d7fcf2>
>
> Similar spirit to e195e6f614de7a4c4f151ad947578fb69f8917f0,
> this moves the Book…markable registration to DiscoursePluginRegistry
> so plugins which are not enabled do not register additional
> bookmarkable classes.

---

<div class="post-metadata">

### Author: ![xyzzy](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@xyzzy](https://meta.discourse.org/u/xyzzy)
#### Post date: [3월 26, 2023, 6:52오전 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761/3 "2023-03-26T06:52:36Z")

</div>

3.1.0.beta2에서 3.1.0.beta3로 업그레이드하는 도중 정확히 같은 오류를 겪었습니다. 이 문제는 프로덕션 환경에 적용하기 전에 업그레이드를 "연습"하는 데 사용하는 비프로덕션 환경에서 발생했습니다.

제 경우, 오류 발생 후 포럼이 다운되었습니다.

app.yml에서 discourse-data-explorer 플러그인 관련 줄을 제거하고 다시 빌드한 결과 문제가 우회되었습니다.

이 유용한 게시물로 제 시간을 많이 절약해 준 @Ed\_S님께 진심으로 감사드립니다!

---

<div class="post-metadata">

### Author: ![xyzzy](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@xyzzy](https://meta.discourse.org/u/xyzzy)
#### Post date: [3월 26, 2023, 8:52오후 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761/4 "2023-03-26T20:52:16Z")

</div>

참고로, 저는 VM을 몇 번 되돌린 뒤 이 업그레이드를 두 가지 다른 방식으로 다시 시도해 보았습니다:

방법 #1 - 업그레이드를 진행한 뒤, 오류가 발생하자마자 바로 재빌드(rebuild)를 수행합니다.

방법 #2 - app.yml에서 discourse-data-explorer 플러그인을 제거하고 재빌드한 뒤, 다시 app.yml에 discourse-data-explorer 플러그인을 추가하고 재빌드합니다.

두 방식 모두 정상적으로 작동하는 것 같습니다. 또한, 위 재빌드 과정은 설치를 3.1.0.beta3 버전으로 업그레이드하는 효과도 있습니다. 하지만, 방법 #1에서 발생한 오류 때문에 중단된 업그레이드로 인해 일부 파일이나 데이터가 비최적 상태로 남아있을 수 있다는 점이 걱정됩니다. 그래서 프로덕션 환경에서는 방법 #2를 사용하게 될 것입니다.

---

<div class="post-metadata">

### Author: ![stevejr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevejr/32/292622_2.png) [@stevejr](https://meta.discourse.org/u/stevejr)
#### Post date: [10월 2, 2023, 1:03오후 UTC](https://meta.discourse.org/t/upgrade-failed-nomethoderror-undefined-method-register-bookmarkable-for-bookmark-class/258761/5 "2023-10-02T13:03:00Z")

</div>

discourse-data-explorer 플러그인이 설치되지 않은 상태에서 이 오류를 목격한 분이 계신가요?
