summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-20 18:01:04 +0000
committerStan Hu <stanhu@gmail.com>2019-03-20 18:01:04 +0000
commitcc5095edfce2b4d4083a4fb1cdc7c0a1898b9921 (patch)
treefa24f7d342a92296a954283232fe40805161c3c0 /lib
parenta6fe183eb00f8060668e66b80a4afd64f1c5f73f (diff)
parent1c7a2c054b8135afdea6be089c0d04fffaada2eb (diff)
downloadgitlab-ce-cc5095edfce2b4d4083a4fb1cdc7c0a1898b9921.tar.gz
Merge branch '59208-fix-error-500-on-every-page-when-active-broadcast-message-present-after-upgrading-to-11-9-0' into 'master'53956-add-a-new-smoke-test-to-create-a-pipeline
Gracefully handles excluded fields from attributes during serialization on JsonCache Closes #59208 See merge request gitlab-org/gitlab-ce!26368
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/json_cache.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/gitlab/json_cache.rb b/lib/gitlab/json_cache.rb
index 24daad638f4..e4bc437d787 100644
--- a/lib/gitlab/json_cache.rb
+++ b/lib/gitlab/json_cache.rb
@@ -80,8 +80,23 @@ module Gitlab
# when the new_record? method incorrectly returns false.
#
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/9903#note_145329964
- attributes = klass.attributes_builder.build_from_database(raw, {})
- klass.allocate.init_with("attributes" => attributes, "new_record" => new_record?(raw, klass))
+ klass
+ .allocate
+ .init_with(
+ "attributes" => attributes_for(klass, raw),
+ "new_record" => new_record?(raw, klass)
+ )
+ end
+
+ def attributes_for(klass, raw)
+ # We have models that leave out some fields from the JSON export for
+ # security reasons, e.g. models that include the CacheMarkdownField.
+ # The ActiveRecord::AttributeSet we build from raw does know about
+ # these columns so we need manually set them.
+ missing_attributes = (klass.columns.map(&:name) - raw.keys)
+ missing_attributes.each { |column| raw[column] = nil }
+
+ klass.attributes_builder.build_from_database(raw, {})
end
def new_record?(raw, klass)