# Buggy code
def check_should_enable_pagination(input_tokens, parsed_args, parsed_globals, **kwargs):
    normalized_paging_args = ["start_token", "max_items"]
    for token in input_tokens:
        py_name = token.replace("-", "_")
        if (
            getattr(parsed_args, py_name) is not None
            and py_name not in normalized_paging_args
        ):
            # The user has specified a manual (undocumented) pagination arg.
            # We need to automatically turn pagination off.
            logger.debug(
                "User has specified a manual pagination arg. "
                "Automatically setting --no-paginate."
            )
            parsed_globals.paginate = False


# Traceback (ParamValidationError)
2015-03-26 06:10:27,908 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.7.16 Python/2.7.6 Linux/3.13.0-48-generic, botocore version: 0.97.0
2015-03-26 06:10:27,908 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['route53', 'list-resource-record-sets', '--hosted-zone-id', 'XYZABC', '--max-items', '1', '--start-record-name', 'hostname.example.com', '--start-record-type', 'CNAME', '--debug']
2015-03-26 06:10:27,908 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_scalar_parsers at 0x7f4cac5109b0>
2015-03-26 06:10:27,909 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider at 0x7f4cac7d0668>
2015-03-26 06:10:27,925 - MainThread - botocore.hooks - DEBUG - Event service-data-loaded.route53: calling handler <function register_retries_for_service at 0x7f4caccae050>
2015-03-26 06:10:27,928 - MainThread - botocore.handlers - DEBUG - Registering retry handlers for service: route53
2015-03-26 06:10:27,929 - MainThread - botocore.hooks - DEBUG - Event building-command-table.route53: calling handler <function add_waiters at 0x7f4cac75d410>
2015-03-26 06:10:27,931 - MainThread - awscli.clidriver - DEBUG - OrderedDict([(u'hosted-zone-id', <awscli.arguments.CLIArgument object at 0x7f4cac389650>), (u'start-record-name', <awscli.arguments.CLIArgument object at 0x7f4cac3896d0>), (u'start-record-type', <awscli.arguments.CLIArgument object at 0x7f4cac389710>), (u'start-record-identifier', <awscli.arguments.CLIArgument object at 0x7f4cac389410>), (u'max-items', <awscli.arguments.CLIArgument object at 0x7f4cac389750>)])
2015-03-26 06:10:27,931 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.route53.list-resource-record-sets: calling handler <function add_streaming_output_arg at 0x7f4cac8b2410>
2015-03-26 06:10:27,931 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.route53.list-resource-record-sets: calling handler <function add_cli_input_json at 0x7f4cac7cb8c0>
2015-03-26 06:10:27,931 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.route53.list-resource-record-sets: calling handler <function unify_paging_params at 0x7f4cac8b8320>
2015-03-26 06:10:27,932 - MainThread - awscli.customizations.paginate - DEBUG - Modifying paging parameters for operation: ListResourceRecordSets
2015-03-26 06:10:27,932 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.route53.list-resource-record-sets: calling handler <function add_generate_skeleton at 0x7f4cac7cbde8>
2015-03-26 06:10:27,932 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.route53.list-resource-record-sets: calling handler <bound method CliInputJSONArgument.override_required_args of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7f4cac389790>>
2015-03-26 06:10:27,932 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.route53.list-resource-record-sets: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7f4cac389bd0>>
2015-03-26 06:10:27,933 - MainThread - botocore.hooks - DEBUG - Event operation-args-parsed.route53.list-resource-record-sets: calling handler <functools.partial object at 0x7f4cac3831b0>
2015-03-26 06:10:27,934 - MainThread - awscli.customizations.paginate - DEBUG - User has specified a manual pagination arg. Automatically setting --no-paginate.
2015-03-26 06:10:27,934 - MainThread - awscli.customizations.paginate - DEBUG - User has specified a manual pagination arg. Automatically setting --no-paginate.
2015-03-26 06:10:27,934 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.hosted-zone-id: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,934 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.route53.list-resource-record-sets: calling handler <awscli.argprocess.ParamShorthand object at 0x7f4cac5193d0>
2015-03-26 06:10:27,934 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-03-26 06:10:27,934 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'XYZABC' for parameter "hosted_zone_id": u'XYZABC'
2015-03-26 06:10:27,934 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.start-record-name: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,934 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.route53.list-resource-record-sets: calling handler <awscli.argprocess.ParamShorthand object at 0x7f4cac5193d0>
2015-03-26 06:10:27,934 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-03-26 06:10:27,934 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'hostname.example.com' for parameter "start_record_name": u'hostname.example.com'
2015-03-26 06:10:27,934 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.start-record-type: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.route53.list-resource-record-sets: calling handler <awscli.argprocess.ParamShorthand object at 0x7f4cac5193d0>
2015-03-26 06:10:27,935 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-03-26 06:10:27,935 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'CNAME' for parameter "start_record_type": u'CNAME'
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.start-record-identifier: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.max-items: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.cli-input-json: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.starting-token: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.page-size: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.route53.list-resource-record-sets.generate-cli-skeleton: calling handler <function uri_param at 0x7f4cac8edc80>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event calling-command.route53.list-resource-record-sets: calling handler <bound method GenerateCliSkeletonArgument.generate_json_skeleton of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7f4cac389bd0>>
2015-03-26 06:10:27,935 - MainThread - botocore.hooks - DEBUG - Event calling-command.route53.list-resource-record-sets: calling handler <bound method CliInputJSONArgument.add_to_call_parameters of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7f4cac389790>>
2015-03-26 06:10:27,936 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2015-03-26 06:10:27,936 - MainThread - botocore.credentials - INFO - Found credentials in environment variables.
2015-03-26 06:10:27,953 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: route53
2015-03-26 06:10:27,953 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: route53
2015-03-26 06:10:27,957 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.route53.ListResourceRecordSets: calling handler <function fix_route53_ids at 0x7f4caccae578>
2015-03-26 06:10:27,957 - MainThread - botocore.handlers - DEBUG - HostedZoneId XYZABC -> XYZABC
2015-03-26 06:10:27,957 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 183, in main
return command_table[parsed_args.command](remaining, parsed_args)
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 367, in __call__
return command_table[parsed_args.operation](remaining, parsed_globals)
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 534, in __call__
call_parameters, parsed_globals)
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 657, in invoke
**parameters)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 187, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 228, in _make_api_call
api_params, operation_model)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 259, in _convert_to_request_dict
api_params, operation_model)
File "/usr/local/lib/python2.7/dist-packages/botocore/validate.py", line 271, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
ParamValidationError: Parameter validation failed:
Unknown parameter in input: "max_items", must be one of: HostedZoneId, StartRecordName, StartRecordType, StartRecordIdentifier, MaxItems
2015-03-26 06:10:27,958 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

Parameter validation failed:
Unknown parameter in input: "max_items", must be one of: HostedZoneId, StartRecordName, StartRecordType, StartRecordIdentifier, MaxItems

# Fixed code
def check_should_enable_pagination(
    input_tokens, shadowed_args, argument_table, parsed_args, parsed_globals, **kwargs
):
    normalized_paging_args = ["start_token", "max_items"]
    for token in input_tokens:
        py_name = token.replace("-", "_")
        if (
            getattr(parsed_args, py_name) is not None
            and py_name not in normalized_paging_args
        ):
            # The user has specified a manual (undocumented) pagination arg.
            # We need to automatically turn pagination off.
            logger.debug(
                "User has specified a manual pagination arg. "
                "Automatically setting --no-paginate."
            )
            parsed_globals.paginate = False
            # Because we've now disabled pagination, there's a chance that
            # we were shadowing arguments.  For example, we inject a
            # --max-items argument in unify_paging_params().  If the
            # the operation also provides its own MaxItems (which we
            # expose as --max-items) then our custom pagination arg
            # was shadowing the customers arg.  When we turn pagination
            # off we need to put back the original argument which is
            # what we're doing here.
            for key, value in shadowed_args.items():
                argument_table[key] = value