Skip to content

Commit efe56ad

Browse files
committed
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 :).
1 parent cf258bf commit efe56ad

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/mako/lib/schema.mako

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
2-
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type)
2+
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by)
33
%>\
44
## Create new schema with everything.
55
## 's' contains the schema structure from json to build
66
###################################################################################################################
77
###################################################################################################################
88
<%def name="new(s, c)">\
99
<%
10-
## assert s.type == "object"
10+
assert s.type == "object"
1111
markers = schema_markers(s, c)
1212
%>\
1313
<%block filter="rust_doc_comment">\
@@ -18,7 +18,7 @@ pub struct ${s.id}\
1818
% if 'properties' in s:
1919
{
2020
% for pn, p in s.properties.iteritems():
21-
${p.get('description', 'no description provided') | rust_doc_comment}
21+
${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)}
2222
pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)},
2323
% endfor
2424
}

src/mako/lib/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from random import (randint, random, choice, seed)
44
import collections
5+
from copy import deepcopy
56

67
seed(1337)
78

@@ -271,7 +272,6 @@ def nested_type(nt):
271272
else:
272273
assert(is_nested_type_property(nt))
273274
# It's a nested type - we take it literally like $ref, but generate a name for the type ourselves
274-
# This of course assumes
275275
return nested_type_name(sn, pn)
276276
return to_rust_type(sn, pn, nt, allow_optionals=False)
277277

@@ -331,7 +331,7 @@ def iter_nested_types(schemas):
331331
def iter_nested_properties(prefix, properties):
332332
for pn, p in properties.iteritems():
333333
if is_nested_type_property(p):
334-
ns = p.copy()
334+
ns = deepcopy(p)
335335
ns.id = nested_type_name(prefix, pn)
336336
ns[NESTED_TYPE_MARKER] = True
337337
if 'items' in p:
@@ -410,7 +410,7 @@ def method_params(m, required=None, location=None):
410410
continue
411411
if location is not None and p.get('location', '') != location:
412412
continue
413-
np = p.copy()
413+
np = deepcopy(p)
414414
np['name'] = pn
415415
try:
416416
# po = ['part', 'foo']

0 commit comments

Comments
 (0)