[orm-devel] SelectByPrimaryKey problem

Werner F. Bruhin orm-devel@mailman.tux4web.de
Mon, 03 Mar 2003 10:38:36 +0100


Hi Diedrich,

First, you give me too much credit!  Don't think I am thinking ORM 
through, it is more a plowing through.  Overall ORM is still too complex 
for me to grasp all the intricacies.

Got the latest version for this, sorry, but I don't think it works.

I think (no I guess) that the problem comes from returning 
"result.fetchone()" instead of just returning "ret".  

However if I use the following code.

        ret = result.fetchone()
       
        if ret is None:
            raise IllegalPrimaryKey("%s in %s" % (fmt, dbclass.__name__))
        else:
            return ret

It works, BUT we never get IllegalPrimaryKey, instead result.fetchone() 
already raises an exception (if key is illegal) for an empty result (see 
below), as the stack shows were we are coming from isn't that already 
good enough.

    w2 = ds.selectByPrimaryKey(test, 450)
  File "C:\Python22\lib\site-packages\orm\datasource.py", line 338, in 
selectByPrimaryKey
    ret = result.fetchone()
  File "C:\Python22\lib\site-packages\orm\datasource.py", line 625, in 
fetchone
    queryResult.fetchone(self))
  File "C:\Python22\lib\site-packages\orm\dbclass.py", line 158, in 
_fromTuple
    if tpl == None: raise EmptyResultError()
orm.errors.EmptyResultError

See you
Werner

Diedrich Vorberg wrote:

>I've modified the selectByPrimaryKey() method to check the value 
>returned by fetchone() to determine whether the key is valid.
>
>Diedrich
>  
>