fix(util): deepcopy dicts instead

It was possible for writes to happen in nested dicts, causing global
data to change and confuse the system.
Not that I wouldn't be aware of that danger, but apparently I didn't
see the recursiveness of the call tree :).
This commit is contained in:
Sebastian Thiel
2015-03-11 08:40:05 +01:00
parent cf258bf4e5
commit efe56ad250
2 changed files with 6 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type)
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by)
%>\
## Create new schema with everything.
## 's' contains the schema structure from json to build
@@ -7,7 +7,7 @@
###################################################################################################################
<%def name="new(s, c)">\
<%
## assert s.type == "object"
assert s.type == "object"
markers = schema_markers(s, c)
%>\
<%block filter="rust_doc_comment">\
@@ -18,7 +18,7 @@ pub struct ${s.id}\
% if 'properties' in s:
{
% for pn, p in s.properties.iteritems():
${p.get('description', 'no description provided') | rust_doc_comment}
${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)}
pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)},
% endfor
}

View File

@@ -2,6 +2,7 @@ import re
import os
from random import (randint, random, choice, seed)
import collections
from copy import deepcopy
seed(1337)
@@ -271,7 +272,6 @@ def to_rust_type(sn, pn, t, allow_optionals=True):
else:
assert(is_nested_type_property(nt))
# It's a nested type - we take it literally like $ref, but generate a name for the type ourselves
# This of course assumes
return nested_type_name(sn, pn)
return to_rust_type(sn, pn, nt, allow_optionals=False)
@@ -331,7 +331,7 @@ def iter_nested_types(schemas):
def iter_nested_properties(prefix, properties):
for pn, p in properties.iteritems():
if is_nested_type_property(p):
ns = p.copy()
ns = deepcopy(p)
ns.id = nested_type_name(prefix, pn)
ns[NESTED_TYPE_MARKER] = True
if 'items' in p:
@@ -410,7 +410,7 @@ def method_params(m, required=None, location=None):
continue
if location is not None and p.get('location', '') != location:
continue
np = p.copy()
np = deepcopy(p)
np['name'] = pn
try:
# po = ['part', 'foo']