From: kedder Date: Mon, 17 Mar 2003 22:03:08 +0000 (+0000) Subject: checked to make sure that the restored item doesn't clash with a new item using the... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cd65267f45debbc41affedbc786870084d0ff420;p=roundup.git checked to make sure that the restored item doesn't clash with a new item using the same key value git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1597 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 258b4da..c167c3c 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.112 2003-03-16 22:24:54 kedder Exp $ +#$Id: back_anydbm.py,v 1.113 2003-03-17 22:03:04 kedder Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -1328,9 +1328,18 @@ class Class(hyperdb.Class): if self.db.journaltag is None: raise DatabaseError, 'Database open read-only' - self.fireAuditors('restore', nodeid, None) - node = self.db.getnode(self.classname, nodeid) + # check if key property was overrided + key = self.getkey() + try: + id = self.lookup(node[key]) + except KeyError: + pass + else: + raise KeyError, "Key property (%s) of retired node clashes with \ + existing one (%s)" % (key, node[key]) + # Now we can safely restore node + self.fireAuditors('restore', nodeid, None) del node[self.db.RETIRED_FLAG] self.db.setnode(self.classname, nodeid, node) if self.do_journal: diff --git a/roundup/backends/back_metakit.py b/roundup/backends/back_metakit.py index 8eae694..13a6573 100755 --- a/roundup/backends/back_metakit.py +++ b/roundup/backends/back_metakit.py @@ -1,4 +1,4 @@ -# $Id: back_metakit.py,v 1.42 2003-03-16 22:24:54 kedder Exp $ +# $Id: back_metakit.py,v 1.43 2003-03-17 22:03:04 kedder Exp $ ''' Metakit backend for Roundup, originally by Gordon McMillan. @@ -684,6 +684,18 @@ class Class: ''' if self.db.journaltag is None: raise hyperdb.DatabaseError, 'Database open read-only' + + # check if key property was overrided + key = self.getkey() + keyvalue = self.get(nodeid, key) + try: + id = self.lookup(keyvalue) + except KeyError: + pass + else: + raise KeyError, "Key property (%s) of retired node clashes with \ + existing one (%s)" % (key, keyvalue) + # Now we can safely restore node self.fireAuditors('restore', nodeid, None) view = self.getview(1) ndx = view.find(id=int(nodeid)) diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 1c60cc7..27b5caf 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.44 2003-03-16 22:24:55 kedder Exp $ +# $Id: rdbms_common.py,v 1.45 2003-03-17 22:03:08 kedder Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -1486,8 +1486,18 @@ class Class(hyperdb.Class): if self.db.journaltag is None: raise DatabaseError, 'Database open read-only' - self.fireAuditors('restore', nodeid, None) + node = self.db.getnode(self.classname, nodeid) + # check if key property was overrided + key = self.getkey() + try: + id = self.lookup(node[key]) + except KeyError: + pass + else: + raise KeyError, "Key property (%s) of retired node clashes with \ + existing one (%s)" % (key, node[key]) + self.fireAuditors('restore', nodeid, None) # use the arg for __retired__ to cope with any odd database type # conversion (hello, sqlite) sql = 'update _%s set __retired__=%s where id=%s'%(self.classname, diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index f78be25..4ab2226 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: hyperdb.py,v 1.86 2003-02-26 04:55:57 richard Exp $ +# $Id: hyperdb.py,v 1.87 2003-03-17 22:03:03 kedder Exp $ """ Hyperdatabase implementation, especially field types. @@ -416,6 +416,13 @@ class Class: """ raise NotImplementedError + def restore(self, nodeid): + '''Restpre a retired node. + + Make node available for all operations like it was before retirement. + ''' + raise NotImplementedError + def is_retired(self, nodeid): '''Return true if the node is rerired ''' diff --git a/test/test_db.py b/test/test_db.py index e686094..bc6720e 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_db.py,v 1.77 2003-03-16 22:24:56 kedder Exp $ +# $Id: test_db.py,v 1.78 2003-03-17 22:03:08 kedder Exp $ import unittest, os, shutil, time @@ -273,6 +273,8 @@ class anydbmDBTestCase(MyTestCase): # use the key again now that the old is retired newid2 = self.db.user.create(username="spam") self.assertNotEqual(newid, newid2) + # try to restore old node. this shouldn't succeed! + self.assertRaises(KeyError, self.db.user.restore, newid) def testRetire(self): self.db.issue.create(title="spam", status='1') @@ -926,7 +928,7 @@ def suite(): unittest.makeSuite(anydbmDBTestCase, 'test'), unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') ] -# return unittest.TestSuite(l) + #return unittest.TestSuite(l) from roundup import backends p = []