googleapis/python-datacatalog

Unable to create a policy tag or list the tag from a target taxonomy

noppGithub opened this issue · 4 comments

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version: Ubuntu 20.04 LTS
  • Python version: python --version: 3.8.10
  • pip version: pip --version: 22.3.1
  • google-cloud-datacatalog version: pip show google-cloud-datacatalog :3.9.3

Steps to reproduce

  1. ? Create a taxonomy in asia-southeast1 using the code from python-datacatalog\samples\snippets\data_catalog_ptm_create_taxonomy.py
  2. ? Try to create a policy tag attach to the taxonomy above using the code from python-datacatalog\samples\generated_samples\datacatalog_v1_generated_policy_tag_manager_create_policy_tag_sync.py

Code example

# example

# Create taxonomy
parent = datacatalog_v1.PolicyTagManagerClient.common_location_path(
            project_id, location_id
)
taxonomy = datacatalog_v1.Taxonomy()
taxonomy.display_name = taxonomy_id  # type: ignore
taxonomy.description = "This Taxonomy represents ..."  # type: ignore
try:
    taxonomy = self.client_ptc.create_taxonomy(parent=parent, taxonomy=taxonomy)
except Exception as e:
    print(f"The taxonomy_id={taxonomy_id} is already exists")
    return False
else:
    print(f"Created taxonomy {taxonomy.name}")
    return True

# Create policy tag, this part failed
parent = datacatalog_v1.PolicyTagManagerClient.common_location_path(
    project_id, location_id
)
client = datacatalog_v1.PolicyTagManagerClient()
request = datacatalog_v1.CreatePolicyTagRequest(
    parent=parent,
)
response = client.create_policy_tag(request=request)
print(response)

Stack trace

Traceback (most recent call last):
  File "d:\np\npblind\.venv\lib\site-packages\google\api_core\grpc_helpers.py", line 72, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "d:\np\npblind\.venv\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "d:\np\npblind\.venv\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.INVALID_ARGUMENT
        details = "Request contains an invalid argument."
        debug_error_string = "UNKNOWN:Error received from peer ipv4:172.217.25.202:443 {grpc_message:"Request contains an invalid argument.", grpc_status:3, created_time:"2022-12-02T04:23:19.522059716+00:00"}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\nnopp\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\nnopp\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\nnopp\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "d:\np\npblind\npblind\core\tools.py", line 85, in <module>
    npb.create_policy_tag(taxonomy_id=taxonomy_name, location_id=location_id)
  File "d:\np\npblind\npblind\core\tools.py", line 75, in create_policy_tag
    response = client.create_policy_tag(request=request)
  File "d:\np\npblind\.venv\lib\site-packages\google\cloud\datacatalog_v1\services\policy_tag_manager\client.py", line 1132, in create_policy_tag
    response = rpc(
  File "d:\np\npblind\.venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "d:\np\npblind\.venv\lib\site-packages\google\api_core\grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

I am getting the same error

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNIMPLEMENTED
        details = "Received http2 header with status: 404"
        debug_error_string = "UNKNOWN:Error received from peer ipv4:74.125.193.95:443 {created_time:"2022-12-12T16:45:18.560286+00:00", grpc_status:12, grpc_message:"Received http2 header with status: 404"}"
>

when calling the list policy tags method

    client = datacatalog_v1.PolicyTagManagerClient()

    # Initialize request argument(s)
    request = datacatalog_v1.ListTaxonomiesRequest(
        parent="***",
    )

    # Make the request
    page_result = client.list_taxonomies(request=request)

For the issue in #449 (comment), the following code works:

from google.cloud.datacatalog_v1 import PolicyTagManagerClient,ListTaxonomiesRequest

client = PolicyTagManagerClient()

# Initialize request argument(s)
request = ListTaxonomiesRequest(
    parent="projects/<project>/locations/<location>",
)

# Make the request
page_result = client.list_taxonomies(request=request)

print(page_result)

Hi @parthea thanks for coming back! yes I figured that out back in December and forgot to comment

For the error message in the original post, I was able to reproduce the issue. The problem appears to be that the parent field in CreatePolicyTagRequest needs to include information about the taxonomy.

I tried

parent = PolicyTagManagerClient.common_location_path(
    'PROJECT', 'LOCATION'
)
client = datacatalog_v1.PolicyTagManagerClient()
request = datacatalog_v1.CreatePolicyTagRequest(
    parent=parent,
)

but I received error

400 Request contains an invalid argument. [detail: "[ORIGINAL ERROR] generic::invalid_argument: invalid name \'projects/<PROJECT>/locations/<LOCATION>\'"

The correct format is parent="projects/<PROJECT>/locations/<LOCATION>/taxonomies/<TAXONOMY>"

parent="projects/<PROJECT>/locations/<LOCATION>/taxonomies/<TAXONOMY>"
client = datacatalog_v1.PolicyTagManagerClient()
request = datacatalog_v1.CreatePolicyTagRequest(
    parent=parent,
)

googleapis/gapic-generator-python#1640 will track improving the automatically generated sample code to provide better sample snippets with examples for values.

I'm going to close this issue as we're tracking the documentation improvements in googleapis/gapic-generator-python#1640.