[Bug 1120322] Re: update-manager crashed with UnboundLocalError in show_diff(): local variable 'line_number' referenced before assignment

Robert Collins 1120322 at bugs.launchpad.net
Thu Feb 28 20:24:08 UTC 2013


So, this is the loop http://bazaar.launchpad.net/~aptdaemon-
developers/aptdaemon/main/view/head:/aptdaemon/gtk3widgets.py#L1114

        for line in difflib.unified_diff(from_lines, to_lines, lineterm=""):
            if line.startswith("@@"):
                match = re.match(self.REGEX_RANGE, line)
                if not match:
                    continue
                line_number = int(match.group("from_start"))
                if line_number > 1:
                    insert_tagged_text(iter, self.ELLIPSIS, "default")
            elif line.startswith("---") or line.startswith("+++"):
                continue

Note the 'if not match: continue' after the REGEX_RANGE lookup - and REGEX_RANGE is:
    REGEX_RANGE = "^@@ \-(?P<from_start>[0-9]+),(?P<from_context>[0-9]+) " \
                  "\+(?P<to_start>[0-9]+),(?P<to_context>[0-9]+) @@"

Now difflib.py has this for its output:
        first, last = group[0], group[-1]
        file1_range = _format_range_unified(first[1], last[2])
        file2_range = _format_range_unified(first[3], last[4])
        yield '@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm)

And if you look at _format_range_unified it has this:
    # Per the diff spec at http://www.unix.org/single_unix_specification/
    beginning = start + 1     # lines start numbering with one
    length = stop - start
    if length == 1:
        return '{}'.format(beginning)
    if not length:
        beginning -= 1        # empty ranges begin at line just before the range
    return '{},{}'.format(beginning, length)

So if the diff range is precisely 1 line long, the output will be
@@ -12 +12,13 @@
But the regex aptdaemon has expects x,y never just x.

So - bad regex, fix that and you should be good. May need to tweak the
assignment code of course.

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to aptdaemon in Ubuntu.
https://bugs.launchpad.net/bugs/1120322

Title:
  update-manager crashed with UnboundLocalError in show_diff(): local
  variable 'line_number' referenced before assignment

Status in Aptdaemon:
  Confirmed
Status in “aptdaemon” package in Ubuntu:
  Triaged
Status in “aptdaemon” source package in Precise:
  Triaged

Bug description:
  At the same time as the crash appeared, I got a box for Keep/Renew Steam config file. 
  I was however no able to click on either Keep/Renew.

  ProblemType: Crash
  DistroRelease: Ubuntu 13.04
  Package: update-manager 1:0.181
  ProcVersionSignature: Ubuntu 3.8.0-4.8-generic 3.8.0-rc6
  Uname: Linux 3.8.0-4-generic x86_64
  NonfreeKernelModules: nvidia
  ApportVersion: 2.8-0ubuntu4
  Architecture: amd64
  Date: Sat Feb  9 14:05:09 2013
  ExecutablePath: /usr/bin/update-manager
  GsettingsChanges:
   b'com.ubuntu.update-manager' b'first-run' b'false'
   b'com.ubuntu.update-manager' b'launch-time' b'1360363834'
   b'com.ubuntu.update-manager' b'show-details' b'true'
   b'com.ubuntu.update-manager' b'window-height' b'625'
   b'com.ubuntu.update-manager' b'window-width' b'591'
  InstallationDate: Installed on 2012-08-22 (170 days ago)
  InstallationMedia: Ubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
  InterpreterPath: /usr/bin/python3.3
  MarkForUpload: True
  PackageArchitecture: all
  ProcCmdline: /usr/bin/python3 /usr/bin/update-manager
  ProcEnviron:
   LANGUAGE=nb_NO:nb:no_NO:no:nn_NO:nn:en
   PATH=(custom, no user)
   XDG_RUNTIME_DIR=<set>
   LANG=nb_NO.UTF-8
   SHELL=/bin/bash
  PythonArgs: ['/usr/bin/update-manager']
  SourcePackage: update-manager
  Title: update-manager crashed with UnboundLocalError in show_diff(): local variable 'line_number' referenced before assignment
  UpgradeStatus: Upgraded to raring on 2013-01-22 (18 days ago)
  UserGroups: adm cdrom dialout dip lpadmin plugdev sambashare sudo tty

To manage notifications about this bug go to:
https://bugs.launchpad.net/aptdaemon/+bug/1120322/+subscriptions




More information about the foundations-bugs mailing list