-
Notifications
You must be signed in to change notification settings - Fork 77
Closed
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
TL;DR
Transcoder API uses a field named mapping in proto message TextStream which appears to be used in a base class for a proto message, this makes it difficult to use the client library with Transcoder API.
I've noticed that for a somewhat similar case (field type) the autogenerated code added _ to the end of the name of the field making it type_, shouldn't this be done for fields named mapping as well?
One of the Transcoder API customers reported that they were having difficulties using Python client library for Transcoder API to create a job to generate subtitles (TextStream).
Environment details
- Programming language: python
- OS:
- Language runtime version: Python 3.9.6 (default, Aug 17 2021, 15:37:33)
- Package version: pip list
google-api-core 2.0.0
google-auth 2.0.0
google-cloud-video-transcoder 0.5.0
googleapis-common-protos 1.53.0
grpcio 1.39.0
Steps to reproduce
- Save the following code snippet in a file
mapping_issue.py
from google.cloud.video import transcoder_v1
if __name__ == "__main__":
job.config = transcoder_v1.types.JobConfig(
elementary_streams=[
transcoder_v1.types.ElementaryStream(
key="vtt-stream-en",
text_stream=transcoder_v1.types.TextStream(
codec="webvtt",
# The following doesn't work because it looks like that "mapping"
# is a "reserved" argument name in GCP python client libraries
# https://github.com/googleapis/proto-plus-python/blob/main/proto/message.py#L447
mapping=[
transcoder_v1.types.TextStream.TextMapping(
atom_key="atom0",
input_key="srtEN",
input_track=0,
),
],
),
),
],
)
- Create a
Dockerfile
FROM python:3
RUN pip install google-cloud-video-transcoder
WORKDIR /usr/src/app
COPY . .
- Build a docker image and run the code snippet in it
docker build . -t p3 && docker run -it --rm -v ~/.config/gcloud:/root/.config/gcloud p3 python ./mapping_issue.py
- Observe the error
Traceback (most recent call last):
File "/usr/src/app/./mapping_issue.py", line 8, in <module>
text_stream=transcoder_v1.types.TextStream(
File "/usr/local/lib/python3.9/site-packages/proto/message.py", line 494, in __init__
raise TypeError(
TypeError: Invalid constructor input for TextStream: [atom_key: "atom0"
input_key: "srtEN"
]
Workaround
Use python dictionary
from google.cloud.video import transcoder_v1
if __name__ == "__main__":
job.config = transcoder_v1.types.JobConfig(
elementary_streams=[
transcoder_v1.types.ElementaryStream(
key="vtt-stream-en",
text_stream={
"codec": "webvtt",
# Use python dictionary as a workaround
"mapping": [
{
"atom_key": "atom0",
"input_key": "srtEN",
"input_track": 0,
}
],
},
),
],
)
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.