Skip to content

Commit

Permalink
Warn about non-jsonable properties.
Browse files Browse the repository at this point in the history
Once builds are stored in the database, properties that are not
jsonable won't be supported. As it is, there are many places that
don't like non-jsonable properties. Provide a warning for now, to
allow people notice of the change.

Refs #2265.
  • Loading branch information
tomprince committed May 18, 2012
1 parent 3245982 commit 834fb7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
10 changes: 10 additions & 0 deletions master/buildbot/process/properties.py
Expand Up @@ -15,8 +15,10 @@

import collections
import re
import warnings
import weakref
from buildbot import config, util
from buildbot.util import json
from buildbot.interfaces import IRenderable, IProperties
from twisted.internet import defer
from twisted.python.components import registerAdapter
Expand Down Expand Up @@ -119,6 +121,14 @@ def hasProperty(self, name):
has_key = hasProperty

def setProperty(self, name, value, source, runtime=False):
try:
json.dumps(value)
except TypeError:
warnings.warn(
"Non jsonable properties are not explicitly supported and" +
"will be explicitly disallowed in a future version.",
DeprecationWarning, stacklevel=2)

self.properties[name] = (value, source)
if runtime:
self.runtime.add(name)
Expand Down
24 changes: 5 additions & 19 deletions master/buildbot/test/unit/test_process_properties.py
Expand Up @@ -497,14 +497,6 @@ def test_property_colon_plus(self):
"echo projectdefined")
return d

def test_property_renderable(self):
self.props.setProperty("project", FakeRenderable('testing'), "test")
command = Interpolate("echo '%(prop:project)s'")
d = self.build.render(command)
d.addCallback(self.failUnlessEqual,
"echo 'testing'")
return d

def test_nested_property(self):
self.props.setProperty("project", "so long!", "test")
command = Interpolate("echo '%(prop:missing:~%(prop:project)s)s'")
Expand All @@ -513,17 +505,6 @@ def test_nested_property(self):
"echo 'so long!'")
return d

def test_nested_property_deferred(self):
renderable = DeferredRenderable()
self.props.setProperty("missing", renderable, "test")
self.props.setProperty("project", "so long!", "test")
command = Interpolate("echo '%(prop:missing:~%(prop:project)s)s'")
d = self.build.render(command)
d.addCallback(self.failUnlessEqual,
"echo 'so long!'")
renderable.callback(False)
return d

def test_property_substitute_recursively(self):
self.props.setProperty("project", "proj1", "test")
command = Interpolate("echo '%(prop:no_such:-%(prop:project)s)s'")
Expand Down Expand Up @@ -1067,6 +1048,11 @@ def testUpdateFromPropertiesNoRuntime(self):
self.failUnlessEqual(self.props.getProperty('x'), 24)
self.failUnlessEqual(self.props.getPropertySource('x'), 'old')

def test_setProperty_notJsonable(self):
self.props.setProperty("project", FakeRenderable('testing'), "test")
self.props.setProperty("project", object, "test")
self.assertEqual(len(self.flushWarnings([self.test_setProperty_notJsonable])), 2)

# IProperties methods

def test_getProperty(self):
Expand Down

0 comments on commit 834fb7b

Please sign in to comment.