changeset 8541:7a7f6ee0a09e

bug: import/importables fail to set newid correctly. Looks like I broke import when I was fixing a scandir issue. Overindented a couple of lines. This prevented the next used id from being set properly. It also resulted in wierd output when importing (bunches of newlines). Also fixed the two export/import tests to verify the new nextid for all the classes is equal or higher than the old one. Ideally they should be equal, but there is a bug somewhere where we get a double increment in the export/import cycle dropping a number or two.
author John Rouillard <rouilj@ieee.org>
date Mon, 23 Mar 2026 22:22:24 -0400
parents e8d1da6e3571
children a4f017ae1477
files CHANGES.txt roundup/admin.py test/db_test_base.py
diffstat 3 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Mon Mar 23 13:18:41 2026 -0400
+++ b/CHANGES.txt	Mon Mar 23 22:22:24 2026 -0400
@@ -62,6 +62,9 @@
   provides the usage output. Also usage output starts with a newline
   to provide a blank line between the command and the output to
   improve readability. (John Rouillard)
+- fix bug in 2.5.0 where roundup-admin import (or importtable) fails
+  to properly set the next available id for the class. (John Rouillard
+  broke it and fixed it 8-))
   
 Features:
 
--- a/roundup/admin.py	Mon Mar 23 13:18:41 2026 -0400
+++ b/roundup/admin.py	Mon Mar 23 22:22:24 2026 -0400
@@ -1317,6 +1317,7 @@
             file_props = None
             # loop through the file and create a node for each entry
             for n, r in enumerate(reader):
+                # read the file header
                 if file_props is None:
                     file_props = r
                     continue
@@ -1330,10 +1331,11 @@
                 nodeid = hyperdb_class.import_list(file_props, r)
                 if hasattr(hyperdb_class, 'import_files') and import_files:
                     hyperdb_class.import_files(import_dir, nodeid)
-                    maxid = max(maxid, int(nodeid))
+                
+                maxid = max(maxid, int(nodeid))
 
-                # (print to sys.stdout here to allow tests to squash it .. ugh)
-                print(file=sys.stdout)
+            # (print to sys.stdout here to allow tests to squash it .. ugh)
+            print(file=sys.stdout)
 
         return maxid
 
--- a/test/db_test_base.py	Mon Mar 23 13:18:41 2026 -0400
+++ b/test/db_test_base.py	Mon Mar 23 22:22:24 2026 -0400
@@ -3231,6 +3231,9 @@
                 for name in klass.getprops().keys():
                     it[name] = klass.get(id, name)
 
+        # record the newid from the original database
+        orig_newid = {cn: self.db.newid(cn) for cn in self.db.classes.keys()}
+        
         os.mkdir('_test_export')
         try:
             # grab the export
@@ -3356,6 +3359,16 @@
                 rj.sort(key = NoneAndDictComparable)
                 ae(oj, rj)
 
+        # compare the newid's. The new database must always have
+        # newid that is greater or equal to the old newid. Ideally
+        # they should be equal but there is a latent bug where the restored
+        # newid is 1 or 2 higher than the old one.
+        for classname, newid in orig_newid.items():
+            self.assertGreaterEqual(
+                self.db.newid(classname), newid,
+                msg="When comparing newid values for classname:old_val:"
+                " %s:%s" % (classname, newid))
+
         # make sure the retired items are actually imported
         ae(self.db.user.get('4', 'username'), 'blop')
         ae(self.db.issue.get('2', 'title'), 'issue two')
@@ -3376,6 +3389,10 @@
         self.db.config.CSV_FIELD_SIZE = 400
         self.db.commit()
         output = []
+
+        # record the newid from the original database
+        orig_newid = {cn: self.db.newid(cn) for cn in self.db.classes.keys()}
+
         # ugly hack to get stderr output and disable stdout output
         # during regression test. Depends on roundup.admin not using
         # anything but stdout/stderr from sys (which is currently the
@@ -3426,6 +3443,16 @@
 
             # verify the data is loaded.
             self.db.user.getnode("5").values()
+
+            # compare the newid's. The new database must always have
+            # newid that is greater or equal to the old newid. Ideally
+            # they should be equal but there is a latent bug where the restored
+            # newid is 1 or 2 higher than the old one.
+            for classname, newid in orig_newid.items():
+                self.assertGreaterEqual(
+                    self.db.newid(classname), newid,
+                    msg="When comparing newid values for "
+                    "classname:old_val: %s:%s" % (classname, newid))
         finally:
             roundup.admin.sys = sys
             shutil.rmtree('_test_export')

Roundup Issue Tracker: http://roundup-tracker.org/