Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 93754

Summary: unicode package name causes erroneous KeyError (no key provided) in aux_get routine (portage_db_template.check_key())
Product: Portage Development Reporter: Yobbo Bandana <yobbobandana>
Component: CoreAssignee: Portage team <dev-portage>
Status: VERIFIED LATER    
Severity: major    
Priority: High    
Version: 2.1   
Hardware: All   
OS: All   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: a one line patch to portage_db_template.py
patch compatible with python 2.2

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 =
u'gnome-base/control-center-2.8.2')
3. attempt portage.portdb.aux_get(package_name, ["IUSE"]) (or anything in
portage.auxdbkeys)

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/portage.py", line 5239, in aux_get
    if doregen or not
self.eclassdb.is_current(mylocation,cat,pkg,self.auxdb[mylocation][cat][pkg]["INHERITED"].split()):
  File "/usr/lib/portage/pym/portage.py", 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/portage_db_cpickle.py", line 37, in has_key
    self.check_key(key)
  File "/usr/lib/portage/pym/portage_db_template.py", 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)
False
>>> isinstance(e,basestring)
True


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

--- /usr/lib/portage/pym/portage_db_template.py	2005-03-26 17:57:07.000000000 +1200
+++ portage_db_template.py	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 portage_db_template.py
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 
though. 
 
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.