1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/python2.4
# Copyright 2007 Canonical Ltd. All rights reserved.
# pylint: disable-msg=C0103,W0403
"""Check for invalid TeamParticipation entries.
These are the ones for which there are no active TeamMemberships leading to.
This script is usually run on staging to find discrepancies between the
TeamMembership and TeamParticipation tables wich are a good indication of
bugs in the code which maintains the TeamParticipation table.
Ideally there should be database constraints to prevent this sort of
situation, but that's not a simple thing and this should do for now.
"""
import _pythonpath
from canonical.database.sqlbase import cursor
from canonical.launchpad.database import Person
from canonical.lp import initZopeless
if __name__ == '__main__':
ztm = initZopeless(implicitBegin=False)
ztm.begin()
query = """
SELECT DISTINCT Person.id
FROM Person, TeamParticipation
WHERE Person.id = Teamparticipation.person
AND TeamParticipation.team != Person.id
"""
cur = cursor()
cur.execute(query)
people_ids = cur.fetchall()
ztm.abort()
batch = people_ids[:50]
people_ids = people_ids[50:]
while batch:
for [id] in batch:
ztm.begin()
person = Person.get(id)
for team in person.teams_indirectly_participated_in:
try:
path = person.findPathToTeam(team)
except AssertionError, e:
print ("Invalid teamParticipation entry for %s (%d) on %s "
"(%d) -- there's no team membership leading to that"
% (person.unique_displayname, person.id,
team.unique_displayname, team.id))
ztm.abort()
batch = people_ids[:50]
people_ids = people_ids[50:]
|