Unattended Upgrades failing with variable reference error

Bug #1798951 reported by Knut Ahlers
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
unattended-upgrades (Ubuntu)
New
Undecided
Unassigned

Bug Description

When running unattended-upgrades with auto-remove enabled the script complains about a variable being referenced before assignment:

```
# unattended-upgrade -d
[...]
Removing unused kernel packages: linux-image-4.15.0-32-generic linux-modules-4.15.0-32-generic
Keeping 2 auto-removable package(s) because it would also remove the following packages which should be kept in this step: [...]
Traceback (most recent call last):
  File "/usr/bin/unattended-upgrade", line 1991, in <module>
    sys.exit(main(options))
  File "/usr/bin/unattended-upgrade", line 1791, in main
    options.verbose or options.debug, options.dry_run)
  File "/usr/bin/unattended-upgrade", line 1480, in do_auto_remove
    if res:
UnboundLocalError: local variable 'res' referenced before assignment
```

This causes the apt-daily-upgrade.service to "fail" which then again causes no updates to be installed, which means the package does not fulfil its purpose:

```
# systemctl status apt-daily-upgrade.service
● apt-daily-upgrade.service - Daily apt upgrade and clean activities
   Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.service; static; vendor preset: enabled)
   Active: inactive (dead) since Sat 2018-10-20 06:17:09 CEST; 6h ago
     Docs: man:apt(8)
 Main PID: 32708 (code=exited, status=0/SUCCESS)

Oct 20 06:16:00 myhost systemd[1]: Starting Daily apt upgrade and clean activities...
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: Traceback (most recent call last):
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: File "/usr/bin/unattended-upgrade", line 1991, in <module>
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: sys.exit(main(options))
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: File "/usr/bin/unattended-upgrade", line 1791, in main
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: options.verbose or options.debug, options.dry_run)
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: File "/usr/bin/unattended-upgrade", line 1480, in do_auto_remove
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: if res:
Oct 20 06:17:09 myhost apt.systemd.daily[32708]: UnboundLocalError: local variable 'res' referenced before assignment
Oct 20 06:17:09 myhost systemd[1]: Started Daily apt upgrade and clean activities.

# apt-get --just-print upgrade | grep ^Inst | wc -l
99
```

Mapped to the current source code of the script within the bionic branch the error occurs in this line:

https://git.launchpad.net/ubuntu/+source/unattended-upgrades/tree/unattended-upgrade?h=ubuntu/bionic&id=165a91cd44a77a03a83c64cd3812831ba26e3a80#n1418

Used version of the package:

```
# apt-cache policy unattended-upgrades
unattended-upgrades:
  Installed: 1.1ubuntu1.18.04.5
  Candidate: 1.1ubuntu1.18.04.5
  Version table:
 *** 1.1ubuntu1.18.04.5 500
        500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages
        500 http://mirror.hetzner.de/ubuntu/packages bionic-updates/main amd64 Packages
        500 http://mirror.hetzner.de/ubuntu/packages bionic-updates/main i386 Packages
        100 /var/lib/dpkg/status
     1.1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu bionic/main i386 Packages
        500 http://mirror.hetzner.de/ubuntu/packages bionic/main amd64 Packages
        500 http://mirror.hetzner.de/ubuntu/packages bionic/main i386 Packages
```

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.