From 6c2a61b1fb436ceff6c90714fb1250487327f6d3 Mon Sep 17 00:00:00 2001 From: Nigel Heron Date: Mon, 1 Feb 2016 15:56:03 -0500 Subject: [PATCH] Fixes removal of non-exemptable operations --- .../error_handling/handle_policy_violation_error.py | 13 ++++++++----- .../error_handling/handle_policy_violation_error.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/adwords/v201506/error_handling/handle_policy_violation_error.py b/examples/adwords/v201506/error_handling/handle_policy_violation_error.py index ccf35075..1c341de2 100755 --- a/examples/adwords/v201506/error_handling/handle_policy_violation_error.py +++ b/examples/adwords/v201506/error_handling/handle_policy_violation_error.py @@ -71,7 +71,8 @@ def main(client, ad_group_id): operation_index = re.findall(r'operations\[(.*)\]\.', error['fieldPath']) if operation_index: - operation = operations[int(operation_index[0])] + operation_index = int(operation_index[0]) + operation = operations[operation_index] print ('Ad with headline \'%s\' violated %s policy \'%s\'.' % (operation['operand']['ad']['headline'], 'exemptable' if error['isExemptable'] else 'non-exemptable', @@ -86,13 +87,15 @@ def main(client, ad_group_id): operation['exemptionRequests'].append({ 'key': error['key'] }) - else: - # Remove non-exemptable operation - print 'Removing the operation from the request.' - operations.delete(operation) + else: + # Remove non-exemptable operation + print 'Removing the operation from the request.' + operations[operation_index] = None # Defer changing the size of the list else: # Non-policy error returned, re-throw exception. raise e + # Remove the non-exemptable operations + operations = [op for op in operations if op is not None] # Add these ads. Disable "validate only" so the ads will get created. client.validate_only = False diff --git a/examples/adwords/v201509/error_handling/handle_policy_violation_error.py b/examples/adwords/v201509/error_handling/handle_policy_violation_error.py index 9e114b1c..894c7762 100755 --- a/examples/adwords/v201509/error_handling/handle_policy_violation_error.py +++ b/examples/adwords/v201509/error_handling/handle_policy_violation_error.py @@ -71,7 +71,8 @@ def main(client, ad_group_id): operation_index = re.findall(r'operations\[(.*)\]\.', error['fieldPath']) if operation_index: - operation = operations[int(operation_index[0])] + operation_index = int(operation_index[0]) + operation = operations[operation_index] print ('Ad with headline \'%s\' violated %s policy \'%s\'.' % (operation['operand']['ad']['headline'], 'exemptable' if error['isExemptable'] else 'non-exemptable', @@ -86,13 +87,15 @@ def main(client, ad_group_id): operation['exemptionRequests'].append({ 'key': error['key'] }) - else: - # Remove non-exemptable operation - print 'Removing the operation from the request.' - operations.delete(operation) + else: + # Remove non-exemptable operation + print 'Removing the operation from the request.' + operations[operation_index] = None # Defer changing the size of the list else: # Non-policy error returned, re-throw exception. raise e + # Remove the non-exemptable operations + operations = [op for op in operations if op is not None] # Add these ads. Disable "validate only" so the ads will get created. client.validate_only = False