-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix: resolve rare issue where ValueError is not raised when both request and flattened param are set #2258
Conversation
… flattened param are set
… flattened param are set
@@ -327,7 +327,8 @@ async def sample_get_trigger(): | |||
# Create or coerce a protobuf request object. | |||
# - Quick check: If we got a request object, we should *not* have | |||
# gotten any keyword arguments that map to the request. | |||
has_flattened_params = any([name]) | |||
flattened_params = [name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is any(flattened_params)
(what we had before) any different from len([param for param in flattened_params if param is not None]) > 0
? IIUC any
returns True
if any of its elements evaluate to True
, so removing the None
s (which evaluate to False
anyway) would only make a difference if the resulting list has only non-None
falsy-objects (where any
would have returned False
but len(...) > 0
would now return True
). What would be a real example of such objects? Could we capture them in a golden file? (I scanned quickly and didn't see one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have non-None
, falsy objects. The test_nested_messages.proto
that was added to fragment tests is an example of a proto where encounter this problem
There is an example in the stack trace in #2257 (comment)
> await client.my_method(
test_nested_messages.MethodRequest(),
some_message=test_nested_messages.SomeMessage(another_message=None),
)
Specifically any([test_nested_messages.SomeMessage(another_message=None)])
evaluates to False
however test_nested_messages.SomeMessage(another_message=None) is not None
evaluates to True
See screen capture from local debugging of the generated fragment client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see. That's slightly surprising, but I guess the semantics are that if a message has nothing set, it evaluates as False
? That would fit with what you're describing.
Thanks for the explanation!
@@ -327,7 +327,8 @@ async def sample_get_trigger(): | |||
# Create or coerce a protobuf request object. | |||
# - Quick check: If we got a request object, we should *not* have | |||
# gotten any keyword arguments that map to the request. | |||
has_flattened_params = any([name]) | |||
flattened_params = [name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see. That's slightly surprising, but I guess the semantics are that if a message has nothing set, it evaluates as False
? That would fit with what you're describing.
Thanks for the explanation!
Adding |
Let's revisit this PR in January |
Fixes #2257