Skip to content

Commit 919778e

Browse files
authored
Merge branch 'main' into sphinx-8.0
2 parents 7207c7c + f19b931 commit 919778e

File tree

8 files changed

+297
-24
lines changed

8 files changed

+297
-24
lines changed

.github/.OwlBot.lock.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Google LLC
1+
# Copyright 2025 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:2ed982f884312e4883e01b5ab8af8b6935f0216a5a2d82928d273081fc3be562
17-
# created: 2024-11-12T12:09:45.821174897Z
16+
digest: sha256:04c35dc5f49f0f503a306397d6d043685f8d2bb822ab515818c4208d7fb2db3a
17+
# created: 2025-01-16T15:24:11.364245182Z

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- uses: actions/checkout@v4
33-
- name: Set up Python 3.9
33+
- name: Set up Python 3.10
3434
uses: actions/setup-python@v5
3535
with:
36-
python-version: "3.9"
36+
python-version: "3.10"
3737
- name: Install nox.
3838
run: python -m pip install nox
3939
- name: Build the documentation.

.kokoro/docker/docs/requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
nox
2+
gcp-docuploader

.kokoro/docker/docs/requirements.txt

+265-10
Large diffs are not rendered by default.

.kokoro/publish-docs.sh

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export PYTHONUNBUFFERED=1
2020

2121
export PATH="${HOME}/.local/bin:${PATH}"
2222

23-
# Install nox
24-
python3.10 -m pip install --require-hashes -r .kokoro/requirements.txt
25-
python3.10 -m nox --version
26-
2723
# build docs
2824
nox -s docs
2925

proto/marshal/rules/message.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ def to_proto(self, value):
3434
try:
3535
# Try the fast path first.
3636
return self._descriptor(**value)
37-
except (TypeError, ValueError) as ex:
38-
# If we have a TypeError or Valueerror,
37+
except (TypeError, ValueError, AttributeError) as ex:
38+
# If we have a TypeError, ValueError or AttributeError,
3939
# try the slow path in case the error
4040
# was:
4141
# - an int64/string issue.
4242
# - a missing key issue in case a key only exists with a `_` suffix.
4343
# See related issue: https://github.com/googleapis/python-api-core/issues/227.
44-
# - a missing key issue due to nested struct. See: b/321905145.
44+
# - a missing key issue due to nested struct. See: https://github.com/googleapis/proto-plus-python/issues/424.
45+
# - a missing key issue due to nested duration. See: https://github.com/googleapis/google-cloud-python/issues/13350.
4546
return self._wrapper(value)._pb
4647
return value
4748

proto/message.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import collections.abc
1717
import copy
1818
import re
19-
from typing import List, Optional, Type
19+
from typing import Any, Dict, List, Optional, Type
2020
import warnings
2121

2222
import google.protobuf
@@ -558,7 +558,7 @@ def to_dict(
558558
including_default_value_fields=None,
559559
float_precision=None,
560560
always_print_fields_with_no_presence=None,
561-
) -> "Message":
561+
) -> Dict[str, Any]:
562562
"""Given a message instance, return its representation as a python dict.
563563
564564
Args:

tests/test_marshal_types_dates.py

+20
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ class Foo(proto.Message):
241241
assert Foo.pb(foo).ttl.seconds == 120
242242

243243

244+
def test_duration_write_string_nested():
245+
class Foo(proto.Message):
246+
foo_field: duration_pb2.Duration = proto.Field(
247+
proto.MESSAGE,
248+
number=1,
249+
message=duration_pb2.Duration,
250+
)
251+
252+
Foo(foo_field="300s")
253+
254+
class Bar(proto.Message):
255+
bar_field = proto.Field(proto.MESSAGE, number=1, message=Foo)
256+
257+
bar = Bar({"bar_field": {"foo_field": "300s"}})
258+
assert isinstance(bar.bar_field.foo_field, timedelta)
259+
assert isinstance(Bar.pb(bar).bar_field.foo_field, duration_pb2.Duration)
260+
assert bar.bar_field.foo_field.seconds == 300
261+
assert Bar.pb(bar).bar_field.foo_field.seconds == 300
262+
263+
244264
def test_duration_del():
245265
class Foo(proto.Message):
246266
ttl = proto.Field(

0 commit comments

Comments
 (0)