@@ -314,33 +314,31 @@ def maybe_split_groups(self, max_groups):
314
314
:param max_groups: Max group list size
315
315
:return: True if at least one command was split, False if none were split
316
316
"""
317
- new_commands = []
317
+ split_commands = []
318
318
# return True if we split at least once
319
319
maybe_split = False
320
320
valid_step_keys = ['add' , 'addRoles' , 'remove' ]
321
321
for command in self .commands :
322
322
# commands are assumed to contain a single key
323
323
step_key , step_args = next (six .iteritems (command ))
324
- if step_key not in valid_step_keys :
325
- new_commands .append (command )
324
+ if step_key not in valid_step_keys or not isinstance ( step_args , dict ) :
325
+ split_commands .append (command )
326
326
continue
327
- split_commands = [command ]
327
+ new_commands = [command ]
328
328
while True :
329
329
new_command = {step_key : {}}
330
- if not isinstance (command [step_key ], dict ):
331
- break
332
330
for group_type , groups in six .iteritems (command [step_key ]):
333
331
if len (groups ) > max_groups :
334
- maybe_split = True
335
332
command [step_key ][group_type ], new_command [step_key ][group_type ] = \
336
333
groups [0 :max_groups ], groups [max_groups :]
337
334
if new_command [step_key ]:
338
- split_commands .append (new_command )
335
+ new_commands .append (new_command )
339
336
command = new_command
337
+ maybe_split = True
340
338
else :
341
339
break
342
- new_commands += split_commands
343
- self .commands = new_commands
340
+ split_commands += new_commands
341
+ self .commands = split_commands
344
342
return maybe_split
345
343
346
344
0 commit comments