Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type annotation for metadata, instead of Sequence[Tuple[str, str]], should be Sequence[Tuple[str, Union[str, bytes]]] #2250

Closed
gabrysiaolsz opened this issue Nov 15, 2024 · 0 comments · Fixed by #2251
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@gabrysiaolsz
Copy link

Environment details

  • OS type and version: Debian GNU/Linux rodete
  • Python version: 3.10.15
  • pip version: 23.0.1
  • gapic-generator version: N/A, bug in already generated library

Steps to reproduce

  1. Install pip install google-cloud-datacatalog-lineage==0.3.9 (as a quick way of getting a generated client)
  2. Create a generated LineageClient
  3. Annotated type for metadata in API methods is Sequence[Tuple[str, str]], but in reality it should be Sequence[Tuple[str, Union[str, bytes]]].

Failing Code example

Sending a pair of str, when the first one has a suffix of "-bin" causes errors:

client.process_open_lineage_run_event(
    request,
    metadata=[
        ('x-goog-ext-512598505-bin', '\n\x08BIGQUERY\x12\x05LOAD1'),
    ]
)

Stack trace

E   TypeError: Binary metadata key="x-goog-ext-512598505-bin" expected bytes, got <class 'str'>

src/python/grpcio/grpc/_cython/_cygrpc/metadata.pyx.pxi:45: TypeError

Working Code example

Sending a pair of str, bytes succeeds:

client.process_open_lineage_run_event(
    request,
    metadata=[
        ('x-goog-ext-512598505-bin', b'\n\x08BIGQUERY\x12\x05LOAD1'),
    ]
)

So the type annotation should be Sequence[Tuple[str, Union[str, bytes]]], to avoid confusion and time wasted on debbuging.
The examples here also show to send str, bytes.

@parthea parthea added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Nov 19, 2024
@parthea parthea removed their assignment Nov 19, 2024
@gabrysiaolsz gabrysiaolsz changed the title Wrong type annotation for metadata, instead of Sequence[Tuple[str, str | bytes]], should be Sequence[Tuple[str, Union[str, bytes]]] Wrong type annotation for metadata, instead of Sequence[Tuple[str, str]], should be Sequence[Tuple[str, Union[str, bytes]]] Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants