Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1b015620
Commit
1b015620
authored
Apr 13, 2018
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recover from errors when a parent is not preloaded
parent
d8dd75ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
app/models/concerns/group_descendant.rb
app/models/concerns/group_descendant.rb
+14
-1
changelogs/unreleased/bvl-shared-groups-on-group-page.yml
changelogs/unreleased/bvl-shared-groups-on-group-page.yml
+6
-0
spec/models/concerns/group_descendant_spec.rb
spec/models/concerns/group_descendant_spec.rb
+16
-1
No files found.
app/models/concerns/group_descendant.rb
View file @
1b015620
...
@@ -37,7 +37,20 @@ module GroupDescendant
...
@@ -37,7 +37,20 @@ module GroupDescendant
parent
||=
preloaded
.
detect
{
|
possible_parent
|
possible_parent
.
is_a?
(
Group
)
&&
possible_parent
.
id
==
child
.
parent_id
}
parent
||=
preloaded
.
detect
{
|
possible_parent
|
possible_parent
.
is_a?
(
Group
)
&&
possible_parent
.
id
==
child
.
parent_id
}
if
parent
.
nil?
&&
!
child
.
parent_id
.
nil?
if
parent
.
nil?
&&
!
child
.
parent_id
.
nil?
raise
ArgumentError
.
new
(
'parent was not preloaded'
)
parent
=
child
.
parent
exception
=
ArgumentError
.
new
<<~
MSG
parent: [GroupDescendant:
#{
parent
.
inspect
}
] was not preloaded for [
#{
child
.
inspect
}
]")
This error is not user facing, but causes a +1 query.
MSG
extras
=
{
parent:
parent
,
child:
child
,
preloaded:
preloaded
.
map
(
&
:full_path
)
}
issue_url
=
'https://gitlab.com/gitlab-org/gitlab-ce/issues/40785'
Gitlab
::
Sentry
.
track_exception
(
exception
,
issue_url:
issue_url
,
extra:
extras
)
end
end
if
parent
.
nil?
&&
hierarchy_top
.
present?
if
parent
.
nil?
&&
hierarchy_top
.
present?
...
...
changelogs/unreleased/bvl-shared-groups-on-group-page.yml
0 → 100644
View file @
1b015620
---
title
:
Show shared projects on group list
list
merge_request
:
18390
author
:
type
:
fixed
spec/models/concerns/group_descendant_spec.rb
View file @
1b015620
...
@@ -79,9 +79,24 @@ describe GroupDescendant, :nested_groups do
...
@@ -79,9 +79,24 @@ describe GroupDescendant, :nested_groups do
expect
(
described_class
.
build_hierarchy
(
groups
)).
to
eq
(
expected_hierarchy
)
expect
(
described_class
.
build_hierarchy
(
groups
)).
to
eq
(
expected_hierarchy
)
end
end
it
'tracks the exception when a parent was not preloaded'
do
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_exception
).
and_call_original
expect
{
GroupDescendant
.
build_hierarchy
([
subsub_group
])
}.
to
raise_error
(
ArgumentError
)
end
it
'recovers if a parent was not reloaded by querying for the parent'
do
expected_hierarchy
=
{
parent
=>
{
subgroup
=>
subsub_group
}
}
# this does not raise in production, so stubbing it here.
allow
(
Gitlab
::
Sentry
).
to
receive
(
:track_exception
)
expect
(
GroupDescendant
.
build_hierarchy
([
subsub_group
])).
to
eq
(
expected_hierarchy
)
end
it
'raises an error if not all elements were preloaded'
do
it
'raises an error if not all elements were preloaded'
do
expect
{
described_class
.
build_hierarchy
([
subsub_group
])
}
expect
{
described_class
.
build_hierarchy
([
subsub_group
])
}
.
to
raise_error
(
'parent was not preloaded'
)
.
to
raise_error
(
/was not preloaded/
)
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment