Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 93754 - unicode package name causes erroneous KeyError (no key provided) in aux_get routine (portage_db_template.check_key())
Summary: unicode package name causes erroneous KeyError (no key provided) in aux_get r...
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: High major (vote)
Assignee: Portage team
Depends on:
Reported: 2005-05-23 19:41 UTC by Yobbo Bandana
Modified: 2007-01-12 06:04 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---

a one line patch to (20040524-patch.diff,437 bytes, patch)
2005-05-24 08:47 UTC, Yobbo Bandana
Details | Diff
patch compatible with python 2.2 (20040526-patch.diff,550 bytes, patch)
2005-05-25 21:12 UTC, Yobbo Bandana
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yobbo Bandana 2005-05-23 19:41:37 UTC
The aux_db_template.check_key() method only checks if the key is an instance of
"str". This should be "basestring" for unicode compatability.

I found the bug while tracking down segfaults in the "porthole" program (a pyGTK
GUI for emerge, using the portage API). If a unicode package name is passed to
the aux_get routine  then a nonsensical KeyError is raised (eg. KeyError: u'No
key provided. key: control-center-2.8.2') and that key is removed from the
aux_get database.

Reproducible: Always
Steps to Reproduce:
1. start python and import portage
2. set up any unicode package name (eg. package_name =
3. attempt portage.portdb.aux_get(package_name, ["IUSE"]) (or anything in

Actual Results:  
>>> e = u"gnome-base/control-center-2.8.2"
>>> portage.portdb.aux_get(e,["IUSE"])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/portage/pym/", line 5239, in aux_get
    if doregen or not
  File "/usr/lib/portage/pym/", line 4980, in is_current
    if not (self.packages[location][cat].has_key(pkg) and
self.packages[location][cat][pkg] and eclass_list):
  File "/usr/lib/portage/pym/", line 37, in has_key
  File "/usr/lib/portage/pym/", line 44, in check_key
    raise KeyError, "No key provided. key: %s" % (key)
KeyError: u'No key provided. key: control-center-2.8.2'

>>> isinstance(e,str)
>>> isinstance(e,basestring)

Expected Results:  
>>> d = "gnome-base/control-center-2.8.2"
>>> portage.portdb.aux_get(d,["IUSE"])
['alsa gstreamer debug debug']

--- /usr/lib/portage/pym/	2005-03-26 17:57:07.000000000 +1200
+++	2005-05-24 14:10:00.000000000 +1200
@@ -40,7 +40,7 @@
 			raise NotImplementedError("db_template.__init__ was overridden")
 	def check_key(self,key):
-		if (not key) or not isinstance(key, str):
+		if (not key) or not isinstance(key, basestring):
 			raise KeyError, "No key provided. key: %s" % (key)
 	def clear(self):
Comment 1 Jason Stubbs (RETIRED) gentoo-dev 2005-05-24 07:45:42 UTC
There's a heap of work that needs to be done to make portage unicode 
compatible. No guarantees until there is an official API. 
Comment 2 Yobbo Bandana 2005-05-24 08:44:24 UTC
Admittedly the unicode wasn't meant to have been passed to portage in the first
place. But that one line in portage_db_template.check_key() was the only place
that seemed to be causing problems. This was just a problem with ascii being
passed on in unicode format, not with an actual unicode name.
Comment 3 Yobbo Bandana 2005-05-24 08:47:58 UTC
Created attachment 59712 [details, diff]
a one line patch to
Comment 4 Jason Stubbs (RETIRED) gentoo-dev 2005-05-25 08:37:15 UTC
Need to check out python-2.2 compatibility on this one. 
Comment 5 Yobbo Bandana 2005-05-25 21:12:37 UTC
Created attachment 59847 [details, diff]
patch compatible with python 2.2

Ahh, sorry. to be compatible with python 2.2 it would have to be
"(isinstance(key, str) or (isinstance(key, unicode))" in stead of
"isinstance(key, basestring)".
Comment 6 Jason Stubbs (RETIRED) gentoo-dev 2005-05-27 08:41:18 UTC
A crude regex showed 14 occurrences throughout portage of issues regarding  
type. However, there's probably other issues too. I don't really like the idea  
of making those 14 places into a test that takes over half a 80-char line 
Will keep this for later when we put together a supported API, which is 
already planned to be released with a requirement of python 2.3. 
Comment 7 Marius Mauch (RETIRED) gentoo-dev 2007-01-12 06:04:59 UTC
Closing due to old age.