application: don't fail sort if a service is down (#82952)
gitea/hobo/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-11-03 10:55:55 +01:00
parent aef9a9b339
commit d96e8117fa
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 26 additions and 4 deletions

View File

@ -60,6 +60,13 @@ def get_object_types():
return object_types
def get_object_type_index(object_type, types):
try:
return types.index(object_type)
except ValueError:
return 99999
class ApplicationError(Exception):
def __init__(self, msg):
self.msg = msg
@ -600,11 +607,17 @@ class AsyncJob(models.Model):
relation.element.type_label = type_labels.get(relation.element.type)
relations = sorted(
relations,
key=lambda a: (a.auto_dependency, types.index(a.element.type), slugify(a.element.name)),
key=lambda a: (
a.auto_dependency,
get_object_type_index(a.element.type, types),
slugify(a.element.name),
),
)
for legacy in result_legacy:
legacy['type_label'] = type_labels.get(legacy['type'])
result_legacy = sorted(result_legacy, key=lambda a: (types.index(a['type']), slugify(a['text'])))
result_legacy = sorted(
result_legacy, key=lambda a: (get_object_type_index(a['type'], types), slugify(a['text']))
)
# build information to display
for relation in relations:
diff = diffs.get(relation.element.type, {}).get(relation.element.slug)

View File

@ -44,6 +44,7 @@ from .models import (
Relation,
UnlinkError,
Version,
get_object_type_index,
get_object_types,
)
from .utils import Requests
@ -99,10 +100,16 @@ class ManifestView(TemplateView):
context['types_by_service'][service].append(object_type)
for relation in context['relations']:
relation.element.type_label = type_labels.get(relation.element.type)
relation.element.type_label = (
type_labels.get(relation.element.type) or _('Unknown (%s)') % relation.element.type
)
context['relations'] = sorted(
context['relations'],
key=lambda a: (a.auto_dependency, types.index(a.element.type), slugify(a.element.name)),
key=lambda a: (
a.auto_dependency,
get_object_type_index(a.element.type, types),
slugify(a.element.name),
),
)
return context

View File

@ -490,6 +490,7 @@ def test_manifest_ordering(app, admin_user, settings):
('cards', 'foooo', False),
('workflows', 'baaaar', False),
('workflows', 'foooo', False),
('unknown', 'foo', False),
]
random.shuffle(objects)
for _type, slug, auto_dependency in objects:
@ -511,6 +512,7 @@ def test_manifest_ordering(app, admin_user, settings):
'Foooo - Card Model remove '
'Baaaar - Workflow remove '
'Foooo - Workflow remove '
'Foo - Unknown (unknown) remove '
'Bar - Form '
'Foo - Form '
'Bar - Card Model '