Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
fd2d5f97
Verified
Commit
fd2d5f97
authored
2 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Require available model versions to apply a template
parent
327037e1
No related branches found
No related tags found
1 merge request
!1949
Require available model versions to apply a template
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/process/serializers/imports.py
+13
-2
13 additions, 2 deletions
arkindex/process/serializers/imports.py
arkindex/process/tests/test_templates.py
+20
-2
20 additions, 2 deletions
arkindex/process/tests/test_templates.py
with
33 additions
and
4 deletions
arkindex/process/serializers/imports.py
+
13
−
2
View file @
fd2d5f97
...
...
@@ -319,9 +319,20 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer):
def
validate
(
self
,
data
):
template_process
=
self
.
context
[
"
template
"
]
unavailable
=
template_process
.
versions
.
filter
(
~
Q
(
state
=
WorkerVersionState
.
Available
)
|
Q
(
docker_image_id
=
None
))
if
unavailable
.
exists
():
unavailable_worker_versions
=
template_process
.
versions
.
filter
(
~
Q
(
state
=
WorkerVersionState
.
Available
)
|
Q
(
docker_image_id
=
None
))
if
unavailable_worker_versions
.
exists
():
raise
ValidationError
(
detail
=
'
This template contains one or more unavailable worker versions and cannot be applied.
'
)
unavailable_model_versions
=
(
template_process
.
worker_runs
.
exclude
(
model_version_id
=
None
)
.
exclude
(
model_version__state
=
'
available
'
)
)
if
unavailable_model_versions
.
exists
():
raise
ValidationError
(
detail
=
'
This template contains one or more unavailable model versions and cannot be applied.
'
)
return
data
...
...
This diff is collapsed.
Click to expand it.
arkindex/process/tests/test_templates.py
+
20
−
2
View file @
fd2d5f97
...
...
@@ -259,7 +259,7 @@ class TestTemplates(FixtureAPITestCase):
def
test_apply_process_template
(
self
):
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
1
8
):
with
self
.
assertNumQueries
(
1
9
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
self
.
process
.
id
)}),
...
...
@@ -293,7 +293,7 @@ class TestTemplates(FixtureAPITestCase):
parents
=
[],
)
# Apply a template that has two other worker runs
with
self
.
assertNumQueries
(
1
8
):
with
self
.
assertNumQueries
(
1
9
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
process
.
id
)}),
...
...
@@ -332,6 +332,24 @@ class TestTemplates(FixtureAPITestCase):
self
.
process
.
refresh_from_db
()
self
.
assertEqual
(
self
.
process
.
template
,
None
)
def
test_apply_process_template_unavailable_model_version
(
self
):
self
.
model_version
.
state
=
ModelVersionState
.
Error
self
.
model_version
.
save
()
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
16
):
response
=
self
.
client
.
post
(
reverse
(
'
api:apply-process-template
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
template
.
id
)}),
data
=
json
.
dumps
({
"
process_id
"
:
str
(
self
.
process
.
id
)}),
content_type
=
'
application/json
'
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
non_field_errors
'
:
[
'
This template contains one or more unavailable model versions and cannot be applied.
'
]})
self
.
process
.
refresh_from_db
()
self
.
assertEqual
(
self
.
process
.
template
,
None
)
def
test_list_templates_ignores_configuration_filter
(
self
):
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertNumQueries
(
7
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment