Skip to content

Commit

Permalink
Use Versioned to ensure SourceStamps have the right types
Browse files Browse the repository at this point in the history
Since SourceStamps are used against the DB, types matter, so this patch
uses styles.Versioned to coerce branch, revision, and patch to the
correct type.
  • Loading branch information
Dustin J. Mitchell committed Feb 16, 2010
1 parent 28d1841 commit a16c976
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion buildbot/sourcestamp.py
@@ -1,9 +1,10 @@
# -*- test-case-name: buildbot.test.test_sourcestamp -*-

from zope.interface import implements
from twisted.persisted import styles
from buildbot import util, interfaces

class SourceStamp(util.ComparableMixin):
class SourceStamp(util.ComparableMixin, styles.Versioned):
"""This is a tuple of (branch, revision, patchspec, changes).
C{branch} is always valid, although it may be None to let the Source
Expand All @@ -23,6 +24,8 @@ class SourceStamp(util.ComparableMixin):
and all must be on the same branch.
"""

persistenceVersion = 1

# all four of these are publically visible attributes
branch = None
revision = None
Expand Down Expand Up @@ -140,4 +143,14 @@ def asDict(self):
result['changes'] = [c.asDict() for c in getattr(self, 'changes', [])]
return result

def upgradeToVersion1(self):
# version 0 was untyped; in version 1 and later, types matter.
print "upgrading sourcestamp to version 1"
if self.branch is not None and not isinstance(self.branch, str):
self.branch = str(self.branch)
if self.revision is not None and not isinstance(self.revision, str):
self.revision = str(self.revision)
if self.patch is not None and not isinstance(self.patch, str):
self.patch = str(self.patch)

# vim: set ts=4 sts=4 sw=4 et:

0 comments on commit a16c976

Please sign in to comment.