summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2641e8d)
raw | patch | inline | side by side (parent: 2641e8d)
author | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 9 Oct 2009 13:54:54 +0000 (13:54 +0000) | ||
committer | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 9 Oct 2009 13:54:54 +0000 (13:54 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4370 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/instance.py | patch | blob | history |
diff --git a/roundup/instance.py b/roundup/instance.py
index 06cff33558c25a761a5084c980de13fdd0a933ab..53fe56bfab597adca7079cbce956320aed2367a4 100644 (file)
--- a/roundup/instance.py
+++ b/roundup/instance.py
# or this is the first time the database is opened,
# do database upgrade checks
if not (self.optimize and self.db_open):
+ # As a consistency check, ensure that every link property is
+ # pointing at a defined class. Otherwise, the schema is
+ # internally inconsistent. This is an important safety
+ # measure as it protects against an accidental schema change
+ # dropping a table while there are still links to the table;
+ # once the table has been dropped, there is no way to get it
+ # back, so it is important to drop it only if we are as sure
+ # as possible that it is no longer needed.
+ classes = db.getclasses()
+ for classname in classes:
+ cl = db.getclass(classname)
+ for propname, prop in cl.getprops().iteritems():
+ if not isinstance(prop, (hyperdb.Link,
+ hyperdb.Multilink)):
+ continue
+ linkto = prop.classname
+ if linkto not in classes:
+ raise ValueError, \
+ ("property %s.%s links to non-existent class %s"
+ % (classname, propname, linkto))
+
db.post_init()
self.db_open = 1
return db