Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

client_info missing in 2.0.0 #37

Closed
tswast opened this issue Aug 11, 2020 · 2 comments
Closed

client_info missing in 2.0.0 #37

tswast opened this issue Aug 11, 2020 · 2 comments
Assignees
Labels
api: cloudkms Issues related to the googleapis/python-kms API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tswast
Copy link

tswast commented Aug 11, 2020

Code example

https://github.com/GoogleCloudPlatform/professional-services/blob/bc79b15c1f8a321eb964b8265e97e3952aca26d5/tools/hive-bigquery/hive_to_bigquery/kms_component.py#L26-L27

Stack trace

# swast @ swast-macbookpro2 in ~/src/professional-services/tools/hive-bigquery on git:issue532-hive-bigquery-kms o [11:01:16] 
$ pytest .
================================================================ test session starts =================================================================
platform darwin -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /Users/swast/src/professional-services/tools/hive-bigquery
collected 3 items                                                                                                                                    

tests/unit/test_bigquery_component.py .                                                                                                        [ 33%]
tests/unit/test_gcs_storage_component.py .                                                                                                     [ 66%]
tests/unit/test_kms_component.py F                                                                                                             [100%]

====================================================================== FAILURES ======================================================================
__________________________________________________________ test_decrypt_symmetric_calls_kms __________________________________________________________

module_under_test = <module 'hive_to_bigquery.kms_component' from '/Users/swast/src/professional-services/tools/hive-bigquery/hive_to_bigquery/kms_component.py'>
mock_kms_client = <MagicMock spec='KeyManagementServiceClient' id='140225081046928'>

    def test_decrypt_symmetric_calls_kms(module_under_test, mock_kms_client):
        mock_kms_client.decrypt.return_value = google.cloud.kms_v1.types.AsymmetricDecryptResponse(plaintext=b"some plain text")
    
>       plaintext = module_under_test.decrypt_symmetric(
            "my-kms-project", "some-location", "a-key-ring", "this-crypto-key",
            b"ABCDEFGHIJKLMNOPQRSTUVWXYZ")

tests/unit/test_kms_component.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
hive_to_bigquery/kms_component.py:27: in decrypt_symmetric
    kms_client = kms_v1.KeyManagementServiceClient(client_info=info)
../../../../miniconda3/envs/kms/lib/python3.8/unittest/mock.py:1079: in __call__
    self._mock_check_sig(*args, **kwargs)
../../../../miniconda3/envs/kms/lib/python3.8/unittest/mock.py:120: in checksig
    sig.bind(*args, **kwargs)
../../../../miniconda3/envs/kms/lib/python3.8/inspect.py:3025: in bind
    return self._bind(args, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Signature (*, credentials: google.auth.credentials.Credentials = None, transport: Union[str, google.cloud.kms_v1.serv...from '/Users/swast/miniconda3/envs/kms/lib/python3.8/site-packages/google/api_core/client_options.py'> = None) -> None>
args = (), kwargs = {'client_info': <google.api_core.gapic_v1.client_info.ClientInfo object at 0x7f88b225f640>}

    def _bind(self, args, kwargs, *, partial=False):
        """Private method. Don't use directly."""
    
        arguments = OrderedDict()
    
        parameters = iter(self.parameters.values())
        parameters_ex = ()
        arg_vals = iter(args)
    
        while True:
            # Let's iterate through the positional arguments and corresponding
            # parameters
            try:
                arg_val = next(arg_vals)
            except StopIteration:
                # No more positional arguments
                try:
                    param = next(parameters)
                except StopIteration:
                    # No more parameters. That's it. Just need to check that
                    # we have no `kwargs` after this while loop
                    break
                else:
                    if param.kind == _VAR_POSITIONAL:
                        # That's OK, just empty *args.  Let's start parsing
                        # kwargs
                        break
                    elif param.name in kwargs:
                        if param.kind == _POSITIONAL_ONLY:
                            msg = '{arg!r} parameter is positional only, ' \
                                  'but was passed as a keyword'
                            msg = msg.format(arg=param.name)
                            raise TypeError(msg) from None
                        parameters_ex = (param,)
                        break
                    elif (param.kind == _VAR_KEYWORD or
                                                param.default is not _empty):
                        # That's fine too - we have a default value for this
                        # parameter.  So, lets start parsing `kwargs`, starting
                        # with the current parameter
                        parameters_ex = (param,)
                        break
                    else:
                        # No default, not VAR_KEYWORD, not VAR_POSITIONAL,
                        # not in `kwargs`
                        if partial:
                            parameters_ex = (param,)
                            break
                        else:
                            msg = 'missing a required argument: {arg!r}'
                            msg = msg.format(arg=param.name)
                            raise TypeError(msg) from None
            else:
                # We have a positional argument to process
                try:
                    param = next(parameters)
                except StopIteration:
                    raise TypeError('too many positional arguments') from None
                else:
                    if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
                        # Looks like we have no parameter for this positional
                        # argument
                        raise TypeError(
                            'too many positional arguments') from None
    
                    if param.kind == _VAR_POSITIONAL:
                        # We have an '*args'-like argument, let's fill it with
                        # all positional arguments we have left and move on to
                        # the next phase
                        values = [arg_val]
                        values.extend(arg_vals)
                        arguments[param.name] = tuple(values)
                        break
    
                    if param.name in kwargs and param.kind != _POSITIONAL_ONLY:
                        raise TypeError(
                            'multiple values for argument {arg!r}'.format(
                                arg=param.name)) from None
    
                    arguments[param.name] = arg_val
    
        # Now, we iterate through the remaining parameters to process
        # keyword arguments
        kwargs_param = None
        for param in itertools.chain(parameters_ex, parameters):
            if param.kind == _VAR_KEYWORD:
                # Memorize that we have a '**kwargs'-like parameter
                kwargs_param = param
                continue
    
            if param.kind == _VAR_POSITIONAL:
                # Named arguments don't refer to '*args'-like parameters.
                # We only arrive here if the positional arguments ended
                # before reaching the last parameter before *args.
                continue
    
            param_name = param.name
            try:
                arg_val = kwargs.pop(param_name)
            except KeyError:
                # We have no value for this parameter.  It's fine though,
                # if it has a default value, or it is an '*args'-like
                # parameter, left alone by the processing of positional
                # arguments.
                if (not partial and param.kind != _VAR_POSITIONAL and
                                                    param.default is _empty):
                    raise TypeError('missing a required argument: {arg!r}'. \
                                    format(arg=param_name)) from None
    
            else:
                if param.kind == _POSITIONAL_ONLY:
                    # This should never happen in case of a properly built
                    # Signature object (but let's have this check here
                    # to ensure correct behaviour just in case)
                    raise TypeError('{arg!r} parameter is positional only, '
                                    'but was passed as a keyword'. \
                                    format(arg=param.name))
    
                arguments[param_name] = arg_val
    
        if kwargs:
            if kwargs_param is not None:
                # Process our '**kwargs'-like parameter
                arguments[kwargs_param.name] = kwargs
            else:
>               raise TypeError(
                    'got an unexpected keyword argument {arg!r}'.format(
                        arg=next(iter(kwargs))))
E               TypeError: got an unexpected keyword argument 'client_info'

../../../../miniconda3/envs/kms/lib/python3.8/inspect.py:3014: TypeError
============================================================== short test summary info ===============================================================
FAILED tests/unit/test_kms_component.py::test_decrypt_symmetric_calls_kms - TypeError: got an unexpected keyword argument 'client_info'

Blocking GoogleCloudPlatform/professional-services#532

@busunkim96
Copy link
Contributor

@tswast This was unintentionally missed, but it looks like the fix is fairly simple. I opened an issue on the generator: googleapis/gapic-generator-python#566

@danoscarmike danoscarmike added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Aug 11, 2020
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Aug 16, 2020
software-dov added a commit to googleapis/gapic-generator-python that referenced this issue Aug 17, 2020
@software-dov
Copy link

Fixed by googleapis/gapic-generator-python#573

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: cloudkms Issues related to the googleapis/python-kms API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants