Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

fix: accessing an unset struct_pb2.Value field does not raise#140

Merged
software-dov merged 1 commit intogoogleapis:masterfrom
software-dov:null-struct-value
Oct 1, 2020
Merged

fix: accessing an unset struct_pb2.Value field does not raise#140
software-dov merged 1 commit intogoogleapis:masterfrom
software-dov:null-struct-value

Conversation

@software-dov
Copy link
Copy Markdown
Contributor

@software-dov software-dov commented Oct 1, 2020

class Foo(proto.Message):
    value = proto.Field(struct_pb2.Value, number=1)

f = Foo()
assert f.value is None          # This should not raise an exception.
assert "value" not in f         # The attribute has _not_ been set.
f.value = None
assert f.value is None
assert "value" in f             # The attribute _has_ been set.

None of the above should raise an exception.

Closes #139

@software-dov software-dov requested a review from a team as a code owner October 1, 2020 20:18
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 1, 2020
class Foo(proto.Message):
    value = proto.Field(struct_pb2.Value, number=1)

f = Foo()
assert f.value is None          # This should not raise an exception.
assert "value" not in f         # The attribute has _not_ been set.
f.value = None
assert f.value is None
assert "value" in f             # The attribute _has_ been set.

None of the above should raise an exception.
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 1, 2020

Codecov Report

Merging #140 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #140   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines          857       856    -1     
  Branches       149       148    -1     
=========================================
- Hits           857       856    -1     
Impacted Files Coverage Δ
proto/marshal/rules/struct.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6888d71...dfe264d. Read the comment docs.

@software-dov software-dov merged commit d045cbf into googleapis:master Oct 1, 2020
@software-dov software-dov deleted the null-struct-value branch October 1, 2020 21:54
@software-dov software-dov self-assigned this Oct 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

struct.Value fields raise an AttributeError when empty

2 participants