Loading and saving comments in the diff of merge requests fails with error 500
Summary
The loading of comments in merge requests fails with an error 500 if at least one comment attached to the diff exists. Creating a comment in the diff fails, too.
Steps to reproduce
- Open an existing merge request (in open, closed, or merged state) with at least one comment attached to the diff.
- Loading of the comments fails (with an appropriate red message box).
- Create a merge request with a non-empty changeset.
- Switch to the "Diff" pane.
- Trying to add a comment fails (with an appropriate red message box).
What is the current bug behavior?
The browsers debug console shows that GETing from "some-group/some-project/-/merge_requests/123/discussions.json?per_page=20" failed with 500.
The browsers debug console shows that POSTing to "some-group/some-project/notes?target_id=1234&target_type=merge_request" failed with 500.
What is the expected correct behavior?
Comments in the diff of a merge request can be fetched and created correctly.
Relevant logs and/or screenshots
Excerpt from the production.log when opening a MR with comments in the diff
Completed 500 Internal Server Error in 685ms (ActiveRecord: 261.0ms | Elasticsearch: 0.0ms | Allocations: 140266)Psych::DisallowedClass (Tried to load unspecified class: Gitlab::Diff::Position):
app/models/diff_discussion.rb:13:in
position' app/models/diff_discussion.rb:51:in
cache_key' app/controllers/concerns/issuable_actions.rb:186:inrender_mr_discussions' app/controllers/concerns/issuable_actions.rb:174:in
discussions' app/controllers/projects/merge_requests_controller.rb:377:indiscussions' app/controllers/application_controller.rb:582:in
block in allow_gitaly_ref_name_caching' lib/gitlab/gitaly_client.rb:323:inallow_ref_name_caching' app/controllers/application_controller.rb:581:in
allow_gitaly_ref_name_caching' app/controllers/application_controller.rb:531:inset_current_admin' lib/gitlab/session.rb:11:in
with_session' app/controllers/application_controller.rb:522:inset_session_storage' lib/gitlab/i18n.rb:107:in
with_locale' lib/gitlab/i18n.rb:113:in `with_user_locale'
Excerpt from the production.log when creating a comment in the diff
Completed 500 Internal Server Error in 65ms (ActiveRecord: 4.2ms | Elasticsearch: 0.0ms | Allocations: 22029)Psych::DisallowedClass (Tried to load unspecified class: Gitlab::Diff::Position):
lib/gitlab/markdown_cache/active_record/extension.rb:21:in
attributes' app/services/notes/build_service.rb:33:in
new_note' app/services/notes/build_service.rb:27:inexecute' app/services/notes/create_service.rb:8:in
execute' app/controllers/concerns/notes_actions.rb:43:increate' app/controllers/application_controller.rb:531:in
set_current_admin' lib/gitlab/session.rb:11:inwith_session' app/controllers/application_controller.rb:522:in
set_session_storage' lib/gitlab/i18n.rb:107:inwith_locale' lib/gitlab/i18n.rb:113:in
with_user_locale'
Output of checks
This issue happens in a Debian package installation.
Results of GitLab environment info
Output of `gitlab-rake gitlab:env:info`
System information System: Current User: git Using RVM: no Ruby Version: 2.7.4p191 Gem Version: 3.2.5 Bundler Version:2.2.5 Rake Version: 13.0.3 Redis Version: 6.0.16 Sidekiq Version:6.4.1 Go Version: unknownGitLab information Version: 15.3.2 Revision: Unknown Directory: /usr/share/gitlab DB Adapter: PostgreSQL DB Version: 13.8 URL: https://localhost HTTP Clone URL: https://localhost/some-group/some-project.git SSH Clone URL: git@localhost:some-group/some-project.git Using LDAP: yes Using Omniauth: no
GitLab Shell Version: 14.11.0 Repository storage paths: default: /var/lib/gitlab/repositories GitLab Shell path: /usr/share/gitlab-shell
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 14.10.0 ? ... OK (14.11.0) Running /usr/share/gitlab-shell/bin/check Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successfulChecking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 0/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) // redacted
Checking LDAP ... Finished
Checking GitLab App ...
Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... yes Systemd unit files or init script up-to-date? ... yes Projects have namespace: ... // redacted, all projects have yes Redis version >= 6.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.4) Git user has default SSH configuration? ... yes Active users: ... 8 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
Googeling the issue I noticed that this might be a yaml serialization related issue. However, Gitlab::Diff::Position
is definitely included in the whitelist config.active_record.yaml_column_permitted_classes
in "config/application.rb".