Skip to content

Commit fff3c89

Browse files
author
Richard Jones
committed
Fixed retirement of items in rdbms imports [SF#841355]
Fixed bug in looking up journal of newly-created items in *dbm backends
1 parent 1b938fa commit fff3c89

15 files changed

+118
-32
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Fixed:
6161
Date +/- Interval now works, and Date - Date also works (produces
6262
an Interval.
6363
- Handle socket timeout exception (thanks Marcus Priesch)
64+
- Fixed retirement of items in rdbms imports (sf bug 841355)
65+
- Fixed bug in looking up journal of newly-created items in *dbm backends
6466

6567

6668
2003-09-29 0.6.2

roundup/backends/back_anydbm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.130 2003-11-10 03:56:39 richard Exp $
18+
#$Id: back_anydbm.py,v 1.131 2003-11-14 00:11:18 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -516,7 +516,11 @@ def getjournal(self, classname, nodeid):
516516
if str(error) == "need 'c' or 'n' flag to open new db":
517517
raise IndexError, 'no such %s %s'%(classname, nodeid)
518518
elif error.args[0] != 2:
519+
# this isn't a "not found" error, be alarmed!
519520
raise
521+
if res:
522+
# we have unsaved journal entries, return them
523+
return res
520524
raise IndexError, 'no such %s %s'%(classname, nodeid)
521525
try:
522526
journal = marshal.loads(db[nodeid])
@@ -936,7 +940,7 @@ def export_list(self, propnames, nodeid):
936940
l.append(repr(value))
937941

938942
# append retired flag
939-
l.append(self.is_retired(nodeid))
943+
l.append(repr(self.is_retired(nodeid)))
940944

941945
return l
942946

roundup/backends/back_bsddb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb.py,v 1.27 2003-09-08 20:39:18 jlgijsbers Exp $
18+
#$Id: back_bsddb.py,v 1.28 2003-11-14 00:11:18 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB.
2121
'''
@@ -105,7 +105,12 @@ def getjournal(self, classname, nodeid):
105105
db = bsddb.btopen(os.path.join(self.dir, 'journals.%s'%classname),
106106
'r')
107107
except bsddb.error, error:
108-
if error.args[0] != 2: raise
108+
if error.args[0] != 2:
109+
# this isn't a "not found" error, be alarmed!
110+
raise
111+
if res:
112+
# we have unsaved journal entries, return them
113+
return res
109114
raise IndexError, 'no such %s %s'%(classname, nodeid)
110115
# more handling of bad journals
111116
if not db.has_key(nodeid):

roundup/backends/back_bsddb3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb3.py,v 1.20 2003-09-08 20:39:18 jlgijsbers Exp $
18+
#$Id: back_bsddb3.py,v 1.21 2003-11-14 00:11:18 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB3.
2121
'''
@@ -105,6 +105,9 @@ def getjournal(self, classname, nodeid):
105105
db = bsddb3.btopen(os.path.join(self.dir, 'journals.%s'%classname),
106106
'r')
107107
except bsddb3._db.DBNoSuchFileError:
108+
if res:
109+
# we have unsaved journal entries, return them
110+
return res
108111
raise IndexError, 'no such %s %s'%(classname, nodeid)
109112
# more handling of bad journals
110113
if not db.has_key(nodeid):

roundup/backends/back_metakit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.52 2003-11-12 03:42:12 richard Exp $
1+
# $Id: back_metakit.py,v 1.53 2003-11-14 00:11:18 richard Exp $
22
'''
33
Metakit backend for Roundup, originally by Gordon McMillan.
44
@@ -1173,7 +1173,7 @@ def export_list(self, propnames, nodeid):
11731173
l.append(repr(value))
11741174

11751175
# append retired flag
1176-
l.append(self.is_retired(nodeid))
1176+
l.append(repr(self.is_retired(nodeid)))
11771177

11781178
return l
11791179

roundup/backends/back_postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def sql_open_connection(self):
2121
try:
2222
self.conn = psycopg.connect(**db)
2323
except psycopg.OperationalError, message:
24-
raise DatabaseError, message
24+
raise hyperdb.DatabaseError, message
2525

2626
self.cursor = self.conn.cursor()
2727

roundup/backends/rdbms_common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.69 2003-11-12 03:42:12 richard Exp $
1+
# $Id: rdbms_common.py,v 1.70 2003-11-14 00:11:19 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1236,7 +1236,7 @@ def export_list(self, propnames, nodeid):
12361236
elif isinstance(proptype, hyperdb.Password):
12371237
value = str(value)
12381238
l.append(repr(value))
1239-
l.append(self.is_retired(nodeid))
1239+
l.append(repr(self.is_retired(nodeid)))
12401240
return l
12411241

12421242
def import_list(self, propnames, proplist):
@@ -1293,6 +1293,9 @@ def import_list(self, propnames, proplist):
12931293
if newid is None:
12941294
newid = self.db.newid(self.classname)
12951295

1296+
# add the node and journal
1297+
self.db.addnode(self.classname, newid, d)
1298+
12961299
# retire?
12971300
if retire:
12981301
# use the arg for __retired__ to cope with any odd database type
@@ -1303,9 +1306,6 @@ def import_list(self, propnames, proplist):
13031306
print >>hyperdb.DEBUG, 'retire', (self, sql, newid)
13041307
self.db.cursor.execute(sql, (1, newid))
13051308

1306-
# add the node and journal
1307-
self.db.addnode(self.classname, newid, d)
1308-
13091309
# extract the extraneous journalling gumpf and nuke it
13101310
if d.has_key('creator'):
13111311
creator = d['creator']

test/db_test_base.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.7 2003-11-12 03:42:13 richard Exp $
18+
# $Id: db_test_base.py,v 1.8 2003-11-14 00:11:19 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -744,6 +744,59 @@ def testFilteringIntervalSort(self):
744744
# XXX add sorting tests for other types
745745
# XXX test auditors and reactors
746746

747+
def testImportExport(self):
748+
# use the filtering setup to create a bunch of items
749+
ae, filt = self.filteringSetup()
750+
self.db.user.retire('3')
751+
self.db.issue.retire('2')
752+
753+
# grab snapshot of the current database
754+
orig = {}
755+
for cn,klass in self.db.classes.items():
756+
cl = orig[cn] = {}
757+
for id in klass.list():
758+
it = cl[id] = {}
759+
for name in klass.getprops().keys():
760+
it[name] = klass.get(id, name)
761+
762+
# grab the export
763+
export = {}
764+
for cn,klass in self.db.classes.items():
765+
names = klass.getprops().keys()
766+
cl = export[cn] = [names+['is retired']]
767+
for id in klass.getnodeids():
768+
cl.append(klass.export_list(names, id))
769+
770+
# shut down this db and nuke it
771+
self.db.close()
772+
self.nuke_database()
773+
774+
# open a new, empty database
775+
os.makedirs(config.DATABASE + '/files')
776+
self.db = self.module.Database(config, 'admin')
777+
setupSchema(self.db, 0, self.module)
778+
779+
# import
780+
for cn, items in export.items():
781+
klass = self.db.classes[cn]
782+
names = items[0]
783+
for itemprops in items[1:]:
784+
klass.import_list(names, itemprops)
785+
786+
# grab snapshot of the current database
787+
for cn, items in orig.items():
788+
klass = self.db.classes[cn]
789+
# ensure retired items are retired :)
790+
l = items.keys(); l.sort()
791+
m = klass.list(); m.sort()
792+
ae(l, m)
793+
for id, props in items.items():
794+
for name, value in props.items():
795+
ae(klass.get(id, name), value)
796+
797+
# make sure the retired items are actually imported
798+
ae(self.db.user.get('3', 'username'), 'blop')
799+
ae(self.db.issue.get('2', 'title'), 'issue two')
747800

748801
class ROTest(MyTestCase):
749802
def setUp(self):

test/test_anydbm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_anydbm.py,v 1.1 2003-10-25 22:53:26 richard Exp $
18+
# $Id: test_anydbm.py,v 1.2 2003-11-14 00:11:19 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

22-
from db_test_base import DBTest, ROTest, SchemaTest, ClassicInitTest
22+
from db_test_base import DBTest, ROTest, SchemaTest, ClassicInitTest, config
2323

2424
class anydbmOpener:
2525
from roundup.backends import anydbm as module
2626

27+
def nuke_database(self):
28+
shutil.rmtree(config.DATABASE)
29+
2730
class anydbmDBTest(anydbmOpener, DBTest):
2831
pass
2932

test/test_bsddb.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_bsddb.py,v 1.1 2003-10-25 22:53:26 richard Exp $
18+
# $Id: test_bsddb.py,v 1.2 2003-11-14 00:11:19 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

22-
from db_test_base import DBTest, ROTest, SchemaTest, \
23-
ClassicInitTest
22+
from db_test_base import DBTest, ROTest, SchemaTest, ClassicInitTest, config
2423
from roundup import backends
2524

2625
class bsddbOpener:
2726
if hasattr(backends, 'bsddb'):
2827
from roundup.backends import bsddb as module
2928

29+
def nuke_database(self):
30+
shutil.rmtree(config.DATABASE)
31+
3032
class bsddbDBTest(bsddbOpener, DBTest):
3133
pass
3234

0 commit comments

Comments
 (0)