web: remove SafeLoader left-over from ZuulJSONEncoder
When a job has a single key vars (or extra-vars/host-vars) that is named after a zuul_node_types such as 'job', then the MappingProxy get a SourceContext and ZuulMark attributes which can not be serialized. The ZuulSafeLoader shouldn't add such node attributes in the first place, but it doesn't seems possible to prevent that. This change also removes the MappingProxyEncoder and replace it by the existing ZuulJSONEncoder. Change-Id: I9fe28a204d41944f86644117c16129234c9d3583
This commit is contained in:
parent
eb7b18b38e
commit
e0c975a980
|
@ -1,6 +1,9 @@
|
|||
- job:
|
||||
name: project1-test1
|
||||
semaphore: test-semaphore
|
||||
vars:
|
||||
semaphore:
|
||||
test: 42
|
||||
run: playbooks/project1-test1.yaml
|
||||
|
||||
- project:
|
||||
|
|
|
@ -17,7 +17,11 @@ import types
|
|||
class ZuulJSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, types.MappingProxyType):
|
||||
return dict(o)
|
||||
d = dict(o)
|
||||
# Always remove SafeLoader left-over
|
||||
d.pop('_source_context', None)
|
||||
d.pop('_start_mark', None)
|
||||
return d
|
||||
return json.JSONEncoder.default(self, o)
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import json
|
|||
import logging
|
||||
import threading
|
||||
import traceback
|
||||
import types
|
||||
|
||||
import gear
|
||||
|
||||
|
@ -25,13 +24,7 @@ from zuul import model
|
|||
from zuul.connection import BaseConnection
|
||||
from zuul.lib import encryption
|
||||
from zuul.lib.config import get_default
|
||||
|
||||
|
||||
class MappingProxyEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, types.MappingProxyType):
|
||||
return dict(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
from zuul.lib.jsonutil import ZuulJSONEncoder
|
||||
|
||||
|
||||
class RPCListener(object):
|
||||
|
@ -361,7 +354,7 @@ class RPCListener(object):
|
|||
output = []
|
||||
for job in jobs:
|
||||
output.append(job.toDict(tenant))
|
||||
gear_job.sendWorkComplete(json.dumps(output, cls=MappingProxyEncoder))
|
||||
gear_job.sendWorkComplete(json.dumps(output, cls=ZuulJSONEncoder))
|
||||
|
||||
def handle_job_list(self, job):
|
||||
args = json.loads(job.arguments)
|
||||
|
@ -431,7 +424,7 @@ class RPCListener(object):
|
|||
config['pipelines'].append(pipeline)
|
||||
result['configs'].append(config)
|
||||
|
||||
gear_job.sendWorkComplete(json.dumps(result, cls=MappingProxyEncoder))
|
||||
gear_job.sendWorkComplete(json.dumps(result, cls=ZuulJSONEncoder))
|
||||
|
||||
def handle_project_list(self, job):
|
||||
args = json.loads(job.arguments)
|
||||
|
|
Loading…
Reference in New Issue