TypeError when two upgrade paths have the same score

Bug #1206866 reported by Loïc Minier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu system image
Fix Released
High
Barry Warsaw

Bug Description

Hi,

Trying to OS update today failed with a python traceback today after we ran a bunch of image builds on the same day; this might be due to dotted version numbers? This is the traceback when running system-image-dbus -v -v manually:
Jul 31 10:29:56 2013 (1879) SystemImage dbus main loop started
Jul 31 10:29:56 2013 (1879) -> [ 1] _get_blacklist_1
Jul 31 10:29:56 2013 (1879) Looking for blacklist: https://system-image.ubuntu.com/gpg/blacklist.tar.xz
Jul 31 10:29:56 2013 (1879) downloading https://system-image.ubuntu.com/gpg/blacklist.tar.xz -> /tmp/system-image/keyring.tar.xz
Jul 31 10:29:56 2013 (1879) downloading https://system-image.ubuntu.com/gpg/blacklist.tar.xz.asc -> /tmp/system-image/keyring.tar.xz.asc
Jul 31 10:29:57 2013 (1879) Local blacklist file: /tmp/system-image/blacklist.tar.xz
Jul 31 10:29:57 2013 (1879) -> [ 2] _get_channel
Jul 31 10:29:57 2013 (1879) Looking for: https://system-image.ubuntu.com/channels.json
Jul 31 10:29:57 2013 (1879) downloading https://system-image.ubuntu.com/channels.json -> /tmp/system-image/channels.json
Jul 31 10:29:57 2013 (1879) downloading https://system-image.ubuntu.com/channels.json.asc -> /tmp/system-image/channels.json.asc
Jul 31 10:30:05 2013 (1879) Local channels file: /tmp/system-image/channels.json
Jul 31 10:30:05 2013 (1879) found channel/device entry: daily/grouper
Jul 31 10:30:05 2013 (1879) -> [ 3] _get_index
Jul 31 10:30:05 2013 (1879) downloading https://system-image.ubuntu.com/daily/grouper/index.json -> /tmp/system-image/index.json
Jul 31 10:30:05 2013 (1879) downloading https://system-image.ubuntu.com/daily/grouper/index.json.asc -> /tmp/system-image/index.json.asc
Jul 31 10:30:12 2013 (1879) -> [ 4] _calculate_winner
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gi/overrides/GLib.py", line 634, in <lambda>
    return (lambda data: callback(*data), user_data)
  File "/usr/lib/python3/dist-packages/systemimage/dbus.py", line 52, in _check_for_update
    update = self._api.check_for_update()
  File "/usr/lib/python3/dist-packages/systemimage/api.py", line 94, in check_for_update
    self._state.run_thru('calculate_winner')
  File "/usr/lib/python3/dist-packages/systemimage/state.py", line 114, in run_thru
    step()
  File "/usr/lib/python3/dist-packages/systemimage/state.py", line 304, in _calculate_winner
    self.winner = config.hooks.scorer().choose(self.candidates)
  File "/usr/lib/python3/dist-packages/systemimage/scores.py", line 47, in choose
    return sorted(zip(self.score(candidates), candidates))[0][1]
TypeError: unorderable types: Image() < Image()
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 139, in apport_excepthook
    os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o640), 'wb') as f:
OSError: [Errno 30] Read-only file system: '/var/crash/_usr_bin_system-image-dbus.0.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gi/overrides/GLib.py", line 634, in <lambda>
    return (lambda data: callback(*data), user_data)
  File "/usr/lib/python3/dist-packages/systemimage/dbus.py", line 52, in _check_for_update
    update = self._api.check_for_update()
  File "/usr/lib/python3/dist-packages/systemimage/api.py", line 94, in check_for_update
    self._state.run_thru('calculate_winner')
  File "/usr/lib/python3/dist-packages/systemimage/state.py", line 114, in run_thru
    step()
  File "/usr/lib/python3/dist-packages/systemimage/state.py", line 304, in _calculate_winner
    self.winner = config.hooks.scorer().choose(self.candidates)
  File "/usr/lib/python3/dist-packages/systemimage/scores.py", line 47, in choose
    return sorted(zip(self.score(candidates), candidates))[0][1]
TypeError: unorderable types: Image() < Image()

Cheers,

Tags: client server
Revision history for this message
Barry Warsaw (barry) wrote : Re: [Bug 1206866] [NEW] [client] Dies with dotted version numbers? - TypeError: unorderable types: Image() < Image()

On Jul 31, 2013, at 10:35 AM, Loïc Minier wrote:

>Trying to OS update today failed with a python traceback today after we ran a
>bunch of image builds on the same day; this might be due to dotted version
>numbers? This is the traceback when running system-image-dbus -v -v
>manually:

I see that system-image.ubuntu.com/daily/ubuntu does have some dotted version
numbers. AFAIK, this is out-of-spec. CC'ing Stephane since this I'm not sure
if this is a bug in the server generation scripts or unspecified but intended
behavior.

The side question is what the client should do in cases where the server is
feeding it incorrect data.

tags: added: client server
Changed in ubuntu-system-image:
assignee: nobody → Stéphane Graber (stgraber)
Revision history for this message
Stéphane Graber (stgraber) wrote :

On Wed, Jul 31, 2013 at 08:21:18AM -0400, Barry Warsaw wrote:
> On Jul 31, 2013, at 10:35 AM, Loïc Minier wrote:
>
> >Trying to OS update today failed with a python traceback today after we ran a
> >bunch of image builds on the same day; this might be due to dotted version
> >numbers? This is the traceback when running system-image-dbus -v -v
> >manually:
>
> I see that system-image.ubuntu.com/daily/ubuntu does have some dotted version
> numbers. AFAIK, this is out-of-spec. CC'ing Stephane since this I'm not sure
> if this is a bug in the server generation scripts or unspecified but intended
> behavior.
>
> The side question is what the client should do in cases where the server is
> feeding it incorrect data.

Whatever the problem is, it's not related to invalid version strings on the
server side. The python code generates integers, so unless someone manually
mangles the index.json, there's no way you'll get dotted version numbers in
there.

As for files containing dotted version numbers, that's because I keep the
version string in those when importing from cdimage. However the spec never
says that the file names should match the version of the image (or we wouldn't
be able to share them at all), so don't look at those.

stgraber@castiana:~$ wget -q http://system-image.ubuntu.com/daily/grouper/index.json -O - | grep "\"version\""
            "version": 20130723
            "version": 20130723
            "version": 20130724
            "version": 20130724
            "version": 20130725
            "version": 20130725
            "version": 20130726
            "version": 20130726
            "version": 20130727
            "version": 20130727
            "version": 20130728
            "version": 20130728
            "version": 20130729
            "version": 20130729
            "version": 20130730
            "version": 20130730
            "version": 20130731
            "version": 20130731
            "version": 20130732
            "version": 20130732

I'm still on vacation and don't have much time to investigate (or even access
the bug report as I have very very limited connectivty at the moment), but I
very much doubt the server side is the problem here.

--
Stéphane Graber
Ubuntu developer
http://www.canonical.com

Revision history for this message
Barry Warsaw (barry) wrote : Re: Dies with dotted version numbers? - TypeError: unorderable types: Image() < Image()

I was not able to reproduce this from a command line upgrade. I think I need to hack phablet-flash now to flash an older image so I can test it out with live data.

summary: - [client] Dies with dotted version numbers? - TypeError: unorderable
- types: Image() < Image()
+ Dies with dotted version numbers? - TypeError: unorderable types:
+ Image() < Image()
Changed in ubuntu-system-image:
assignee: Stéphane Graber (stgraber) → Barry Warsaw (barry)
status: New → In Progress
milestone: none → 0.9.3
importance: Undecided → High
Revision history for this message
Barry Warsaw (barry) wrote :

Oh wow, cool! phablet-flash already got this in yesterday's update.

Revision history for this message
Barry Warsaw (barry) wrote :

I figured this out.

Let's say two candidate upgrade paths have the exact same score, e.g. 40. When we zip the score with the candidates, we'll have a structure roughly like this:

[..., (40, [Image, Image, Image]), (40, [Image, Image, Image]), ...]

When we go to sort this, the default sorting algorithm for tuples is to sort on the first element, then the second element, etc. The first element will be equal, so it will fall back to sorting on the second element. *That* falls back to comparing the lists, which falls back to comparing the individual Images in each list. Images aren't comparable, thus the traceback.

The solution is to add a second element to the sorted tuples which is an ordinal that will never appear twice. That way, the above structure would look like:

[..., (40, 12, [Image, Image, Image]), (40, 13, [Image, Image, Image]), ...]

so sorting will never fallback to the list of Images.

Barry Warsaw (barry)
summary: - Dies with dotted version numbers? - TypeError: unorderable types:
- Image() < Image()
+ TypeError when two upgrade paths have the same score
Barry Warsaw (barry)
Changed in ubuntu-system-image:
status: In Progress → Fix Committed
milestone: 0.9.3 → 1.0
Revision history for this message
Stéphane Graber (stgraber) wrote :

So both my test devices now have that bug, could this be triggered when a device is running a version that's no longer available on system-image.ubuntu.com?

In my case, both my devices are running 20130723 and the oldest available full or delta is 20130726.1, so system-image-cli would be expected to resolve a full straight to the latest available version.

Barry Warsaw (barry)
Changed in ubuntu-system-image:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.