Skip to content
Snippets Groups Projects

Create RecommendedWorkerVersionRetrieve endpoint

Merged ml bonhomme requested to merge wv-rec into release-1.7.2
+ 3
1
@@ -1180,12 +1180,14 @@ class RecommendedWorkerVersionRetrieve(RetrieveAPIView):
# tag_as_int is created by splitting on an eventual '-' so if we have '0.3.2' and '0.3.2-rc2' they both have 32
# as `tag_as_int`. The second ordering by tag (regular alphabetical ordering) ensures that the main version (0.3.2)
# is returned in this case.
# The concatenation of a 0 at the beginning of each tag_as_int ensures that the casting to integer will always work,
# even if after applying the regex we end up with an empty string.
# This will not order such version tags satisfactorily if the '-rc{number}' part goes beyond 9, as this is
# alphabetical ordering so 1 > 10 > 2 > 3 > 4 etc.
return (
self.worker.versions.filter(tag__isnull=False)
.filter(state=WorkerVersionState.Available) \
.annotate(tag_as_int=RawSQL("split_part(regexp_replace(tag, '[^0-9-]', '', 'g'), '-', 1)::int", []))
.annotate(tag_as_int=RawSQL("concat('0', split_part(regexp_replace(tag, '[^0-9-]', '', 'g'), '-', 1))::int", []))
.using("default") \
.select_related("worker__type") \
.distinct() \
Loading