Sorting of Build IDs in project builds gets messed up if you have lots of builds
Bug #1464385 reported by
Caio Begotti
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Capomastro |
Triaged
|
Low
|
Unassigned |
Bug Description
See the screenshot attached and you'll notice I had lots of project builds within a day, so the sorting of Build IDs at the bottom of the UI gets messed up because it's the sorting is a simple one, ignoring multiple digits after the period.
That means more than 10 project builds in the same day might trigger this sorting problem, and that could happen very often if people have scheduled builds instead of manual ones.
To post a comment you must log in.
It's similar to the problem system-image-server had with more than 9 builds in a single day. It may have been easier for them to sort since it's Python code and they could have written a custom sort method.
Apparently the projectbuilds context object is created in projects/views.py, in ProjectBuildLis tView:
def get_queryset(self): objects. filter(
project= self._get_ project_ from_url( ))
return ProjectBuild.
I'm not sure any order_by parameter would give us the order we want. This http:// stackoverflow. com/questions/ 883575/ custom- ordering- in-django suggests simply using Python ordering for smallish data sets:
qs = ProjectBuild. objects. filter(
project= self._get_ project_ from_url( ))
return sorted(qs, key=lambda x: [int(y) for y in x.split('.')])
This orders lists of integers which will behave as we want, with the downside that the elements of the build id *need* to be convertible to int. Example:
>>> sorted( ('2010. 1','2010. 2','2010. 10','2010. 80')) ('2010. 1','2010. 2','2010. 10','2010. 80'), key=lambda x: [int(y) for y in x.split('.')])
['2010.1', '2010.10', '2010.2', '2010.80'] # Bad ordering
>>> sorted(
['2010.1', '2010.2', '2010.10', '2010.80'] # This is good
However, as seen in that stackoverflow answer, this will not work on large sets of builds. The suggested solution, which I'd tend to agree with, is introducing an "order" column to use with order_by() directly in the query set. We could have a data migration which would apply the "split at the dots" for the build ID to populate this column, and then simply incrementally add to it.