Raise AttributeError on attempts to access unset oneof fields (#510)

This commit is contained in:
Alexander Khabarov
2023-07-21 13:26:30 +01:00
committed by GitHub
parent 098989e9e9
commit 6faac1d1ca
11 changed files with 116 additions and 29 deletions

View File

@@ -50,8 +50,10 @@ def test_bytes_are_the_same_for_oneof():
# None of these fields were explicitly set BUT they should not actually be null
# themselves
assert isinstance(message.foo, Foo)
assert isinstance(message2.foo, Foo)
assert not hasattr(message, "foo")
assert object.__getattribute__(message, "foo") == betterproto.PLACEHOLDER
assert not hasattr(message2, "foo")
assert object.__getattribute__(message2, "foo") == betterproto.PLACEHOLDER
assert isinstance(message_reference.foo, ReferenceFoo)
assert isinstance(message_reference2.foo, ReferenceFoo)