Skip to content

Commit 5756b28

Browse files
committed
issue2551142 - Import of retired node ... unique constraint failure.
Title: Import of retired node with username after active node fails with unique constraint failure. Use different way of checking log output. Remove commit and rollback messages. For some reason python 3.4 in CI has different location for our interesting messages. 3.5+ all passed fine. Update upgrading.txt and CHANGES.txt.
1 parent a9cdf70 commit 5756b28

File tree

3 files changed

+94
-10
lines changed

3 files changed

+94
-10
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ Fixed:
133133
(John Rouillard)
134134
- issue2551142 - Import of retired node with username after active
135135
node fails with unique constraint failure. (John Rouillard)
136+
- *** Must run roundup-admin migrate ***
137+
Increment rdbms version from 5 to 6. Mysql rdbms classes were
138+
missing unique key constraint. Found during fix for issue2551142.
139+
See upgrading.txt.
136140

137141
Features:
138142
- issue2550522 - Add 'filter' command to command-line

doc/upgrading.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,80 @@ Contents:
2727
Migrating from 2.0.0 to 2.x.x
2828
=============================
2929

30+
Rdbms version change from 5 to 6 (**)
31+
-------------------------------------
32+
33+
To fix an issue with importing databases, the database has to be
34+
upgraded for rdbms backends.
35+
36+
You should run the ``roundup-admin migrate`` command for your
37+
tracker once you've installed the latest codebase.
38+
39+
Do this before you use the web, command-line or mail interface
40+
and before any users access the tracker.
41+
42+
If successful, this command will respond with either "Tracker
43+
updated" (if you've not previously run it on an RDBMS backend) or
44+
"No migration action required" (if you have run it, or have used
45+
another interface to the tracker, or are using anydbm).
46+
47+
This only changes the schema for the mysql backend. It has no
48+
effect other than upgrading the revision on other rdbms backends.
49+
50+
On the mysql backend it creates the database index that makes
51+
sure the key field for your class is unique.
52+
53+
If your update/migration fails, you will see an::
54+
55+
IntegrityError: (1062, "Duplicate entry '0-NULL' for key '_user_key_retired_idx'")
56+
57+
it means you have two non-retired members of the class with the
58+
same key field. E.G. two non-retired users with the same
59+
username.
60+
61+
Debug this using roundup-admin using the list command. For
62+
example dump the user class by the key field ``username``::
63+
64+
$ roundup-admin -i <tracker_home> list user username
65+
1: admin
66+
2: anonymous
67+
3: demo
68+
4: agent
69+
5: provisional
70+
71+
7: dupe
72+
8: dupe
73+
...
74+
75+
then search the usernames for duplicates. Once you have
76+
identified the duplicate username (``dupe`` above), you should
77+
retire the other active duplicates or change the username for the
78+
duplicate. To retire ``7: dupe``, you run::
79+
80+
roundup-admin -i <tracker_home> retire user7
81+
82+
(use ``restore user7`` if you retired the wrong item). If you
83+
want to rename the entry use::
84+
85+
roundup-admin -i <tracker_home> set user7 username=dupe1
86+
87+
Keep doing this until you have no more duplicates. Then run the
88+
update/migrate again.
89+
90+
If you have duplicate non-retired entries in your database,
91+
please email roundup-users at lists.sourceforge.net. We are
92+
interested in how many issues this has caused. Duplicate creation
93+
should occur only when two or more mysql processes run in
94+
parallel and both of them creating an item with the same key. So
95+
this should be a rare event. The internal duplicate prevention
96+
checks should work in other cases.
97+
98+
For the nerds: if you had a new installation that was created at
99+
version 5, the uniqueness of a key was not enforced at the
100+
database level. If you had a database that was at version 4 and
101+
then upgraded to version 5 you have the uniqueness enforcing
102+
constraint.
103+
30104
Setuptools is now required to install
31105
-------------------------------------
32106

test/db_test_base.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,21 +2957,27 @@ def testImportExport(self):
29572957
# postgres requires commits and rollbacks
29582958
# as part of error recovery, so we get commit
29592959
# logging that we need to account for
2960+
log = []
29602961
if self.db.dbtype == 'postgres':
2961-
log_count=24
2962-
handle_msg_location=16
2963-
# add two since rollback is logged
2964-
success_msg_location = handle_msg_location+2
2962+
# remove commit and rollback log messages
2963+
# so the indexes below work correctly.
2964+
for i in range(0,len(self._caplog.record_tuples)):
2965+
if self._caplog.record_tuples[i][2] not in \
2966+
["commit", "rollback"]:
2967+
log.append(self._caplog.record_tuples[i])
29652968
else:
2966-
log_count=2
2967-
handle_msg_location=0
2968-
success_msg_location = handle_msg_location+1
2969-
self.assertEqual(log_count, len(self._caplog.record_tuples))
2969+
log = self._caplog.record_tuples[:]
2970+
2971+
log_count=2
2972+
handle_msg_location=0
2973+
success_msg_location = handle_msg_location+1
2974+
2975+
self.assertEqual(log_count, len(log))
29702976
self.assertIn('Attempting to handle import exception for id 7:',
2971-
self._caplog.record_tuples[handle_msg_location][2])
2977+
log[handle_msg_location][2])
29722978
self.assertIn('Successfully handled import exception for id 7 '
29732979
'which conflicted with 6',
2974-
self._caplog.record_tuples[success_msg_location][2])
2980+
log[success_msg_location][2])
29752981

29762982
# This is needed, otherwise journals won't be there for anydbm
29772983
self.db.commit()

0 commit comments

Comments
 (0)