cbfeeds icon indicating copy to clipboard operation
cbfeeds copied to clipboard

calling feed.dump(validate=False) still validates reports

Open jjguy opened this issue 10 years ago • 0 comments

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/cballiance/feed_blueprint.py", line 93, in get_feed
    feed_io.write(feed.dump(validate=False))
  File "/usr/lib/python2.6/site-packages/cbfeeds/feed.py", line 25, in dump
    return json.dumps(self.data, cls=CbJSONEncoder, indent=2)
  File "/usr/lib64/python2.6/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib64/python2.6/json/encoder.py", line 367, in encode
    chunks = list(self.iterencode(o))
  File "/usr/lib64/python2.6/json/encoder.py", line 309, in _iterencode
    for chunk in self._iterencode_dict(o, markers):
  File "/usr/lib64/python2.6/json/encoder.py", line 275, in _iterencode_dict
    for chunk in self._iterencode(value, markers):
  File "/usr/lib64/python2.6/json/encoder.py", line 306, in _iterencode
    for chunk in self._iterencode_list(o, markers):
File "/usr/lib64/python2.6/json/encoder.py", line 204, in _iterencode_list
    for chunk in self._iterencode(value, markers):
  File "/usr/lib64/python2.6/json/encoder.py", line 317, in _iterencode
    for chunk in self._iterencode_default(o, markers):
  File "/usr/lib64/python2.6/json/encoder.py", line 323, in _iterencode_default
    newobj = self.default(o)
  File "/usr/lib/python2.6/site-packages/cbfeeds/feed.py", line 14, in default
    return o.dump()
  File "/usr/lib/python2.6/site-packages/cbfeeds/feed.py", line 144, in dump
    self.validate()
  File "/usr/lib/python2.6/site-packages/cbfeeds/feed.py", line 175, in validate
    if not re.match("^[a-zA-Z0-9-_.]+$", self.data["id"]):
  File "/usr/lib64/python2.6/re.py", line 137, in match
    return _compile(pattern, flags).match(string)

Note the following lines:

    feed_io.write(feed.dump(validate=False))
    ...
    return json.dumps(self.data, cls=CbJSONEncoder, indent=2)
    ...
    return o.dump()
    ... 
    self.validate()

The caller passed validate=False() but when each object is passed through CbJSONEncoder, it calls o.dump() -- and triggers validation on the sub-objects.

Recommend:

  • having two CbJSONEncoder classes - one that validates and one that does not
  • updating the CbFeedInfo and CbReport dump() functions to take validate kwarg

jjguy avatar Feb 05 '15 21:02 jjguy