diff options
author | Stan Hu <stanhu@gmail.com> | 2019-03-01 20:02:56 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-03-01 20:02:56 +0300 |
commit | adf71cfa75fb07c54cb2f55126d1f8596e3ab5c3 (patch) | |
tree | fb0661b3a8a6e2eb8b3ad182bf35f00083edd200 /lib | |
parent | 3977421ed1b0cf75ab2a4bdf7c06d7b8c80489f0 (diff) | |
parent | e96f2f248a63cc7115fb52a02b1743f15205e642 (diff) |
Merge branch '9903-geo-selective-sync-by-namespace-is-broken' into 'master'
Fix GitLab::JsonCache when reading a persisted entry back from the cache
See merge request gitlab-org/gitlab-ce!25587
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/json_cache.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/gitlab/json_cache.rb b/lib/gitlab/json_cache.rb index 1adf83739ad..24daad638f4 100644 --- a/lib/gitlab/json_cache.rb +++ b/lib/gitlab/json_cache.rb @@ -71,7 +71,21 @@ module Gitlab end def parse_entry(raw, klass) - klass.new(raw) if valid_entry?(raw, klass) + return unless valid_entry?(raw, klass) + return klass.new(raw) unless klass.ancestors.include?(ActiveRecord::Base) + + # When the cached value is a persisted instance of ActiveRecord::Base in + # some cases a relation can return an empty collection becauses scope.none! + # is being applied on ActiveRecord::Associations::CollectionAssociation#scope + # 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)) + end + + def new_record?(raw, klass) + raw.fetch(klass.primary_key, nil).blank? end def valid_entry?(raw, klass) |