[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#523801: Returns invalid Version objects on packages without candidate versions



On Sun, Apr 12, 2009 at 05:13:43PM +0100, Enrico Zini wrote:
> Package: python-apt
> Version: 0.7.10.1
> Severity: critical
> 
> Hello,
> 
> I'm setting the severity to 'critical' because it causes several other
> packages to break, including goplay, ept-cache and basically anything
> that uses or recommends apt-xapian-index (see #521346, #523737 and
> #523747).
> 
> I'm attaching a short test case.  When run on a system which contains a
> package in status 'config-files' and with no information in the apt
> database, package.candidate gives a version object that throws on every
> single method.  
package.candidate gives exactly what is requested. As you explain below,
when there is no candidate it returns None.

The problem is that the deprecated properties candidate*, etc. expected
candidate to not be None. This was my fault, sorry. (I forgot about cases
where there is no candidate version, because I almost never had one).

> I would rather not have to work around this by wrapping every read of a
> property of Version in try/except, and I wish you can fix this soon,
> because I'm getting several nasty bug reports.

The rule is:
 => Package.candidate and Package.installed can be None
 => Package.versions has at least one version if one is available

So, simply ignore packages which have no candidate / installed (depending
on what you need) and you are fine.

python-apt 0.7.10.2 will change the deprecated properties (e.g. Package.candidateVersion)
back to return None if no candidate is available.

To use the 'candidate' and 'installed' properties, you may have to rework your
code a bit, but this style of coding is much better than checking multiple times
the properties of something which does not exist.

Instead of:
	# 2 lookups of candidate
	print package.candidateVersion or package.installedVersion
	print package.candidateRecord or package.installedRecord

you would write:
	# 1 lookup of candidate
	version = package.candidate or package.installed
	print version.version

When doing this a multiple times you should see a speed improvement,
because you save the GetCandidateVer() lookups for every property.

This means you should always keep a reference to the object returned by
the property instead of accessing the property multiple times.
	

> 
> If you cannot/won't fix it soon, at least let me know.  Please don't
> leave me hanging with a nonfunctional package and no answer for a month
> like you did with #513315.
I'm sorry that this took such a long time, the patch maybe should have been
backported from 0.7.9 to a 0.7.8.1 release.

>     # python-apt should not raise an exception at this point
>     try:
>         dummy = ver.raw_description
It has to raise an exception because you are trying to get a raw description
from a non-existing version.

You should simply check if candidate is None, and then skip the package,
use an installed version or get another version from versions.


-- 
Julian Andres Klode  - Free Software Developer
   Debian Developer  - Contributing Member of SPI
   Ubuntu Member     - Fellow of FSFE

Website: http://jak-linux.org/   XMPP: juliank@jabber.org
Debian:  http://www.debian.org/  SPI:  http://www.spi-inc.org/
Ubuntu:  http://www.ubuntu.com/  FSFE: http://www.fsfe.org/

Attachment: signature.asc
Description: Digital signature


Reply to: