Idiom for partial failures

Rob Gaddi rgaddi at highlandtechnology.invalid
Fri Feb 21 17:51:39 EST 2020


On 2/21/20 9:18 AM, David Wihl wrote:
> Yes, the API has to support partial failures across all six supported
> languages. Not all operations need to be atomic and there is considerable
> efficiency in having multiple operations sent in a single request. Thanks,
> -David
> 
> On Thu, Feb 20, 2020 at 6:07 PM Rob Gaddi <rgaddi at highlandtechnology.invalid>
> wrote:
> 
>> On 2/20/20 9:30 AM, David Wihl wrote:
>>> 
>>> (first post)
>>>
>>> I'm working on the Python client library [0]for the Google Ads API [1].
>> In some cases, we can start a request with a partial failure [2] flag =
>> True. This means that the request may contain say 1000 operations. If any
>> of the operations fail, the request will return with a success status
>> without an exception. Then the developer has to iterate through the list of
>> operation return statuses to determine which specific ones failed (example
>> [3]).
>>>
>>> I believe that it would be more idiomatic in Python (and other languages
>> like Ruby) to throw an exception when one of these partial errors occur.
>> That way there would be the same control flow if a major or minor error
>> occurred.
>>>
>>> The team is asking me for other examples or justification of this being
>> idiomatic of Python. Can you recommend any examples or related best
>> practices?
>>>
>>> [0] https://github.com/googleads/google-ads-python
>>>
>>> [1] https://developers.google.com/google-ads/api/docs/start
>>>
>>> [2]
>> https://developers.google.com/google-ads/api/docs/best-practices/partial-failures
>>>
>>> [3]
>> https://github.com/googleads/google-ads-python/blob/master/examples/error_handling/handle_partial_failure.py
>>>
>>> Thanks!
>>> -David
>>>
>>
>> Potentially stupid question, does your library to the API have to support
>> partial failures?  Sure Google Ads does, but does it really add value to
>> do so?
>> And then you've got to decide what to DO with those partially failed
>> results.
>>
>> You could, as a library, just say "No, this library never sets the
>> partial_failure field.  We only support atomic transactions that fully
>> succeed
>> or fully fail and raise an exception."  Makes your life a lot easier; so
>> unless
>> it makes your customer's lives a lot harder...
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>

In that case, I think Richard Damon's answer smells rightest.  A partial failure 
is a partial success and should not trigger a mandatory flow-control change, 
which is what an exception is.

If there is any information in the successes, then I'd expect an operation like 
this to return me a list corresponding 1-to-1 with the list of operations such 
that I could:

results = do_the_thing()
for op, result in zip(operations, results):
    if isinstance(result, GoogleApiError):
       deal_with_error(op, result)

If successes have nothing to add to the party, then I'd expect the operation to 
return a list containing only the errors, and an empty list means no errors.


More information about the Python-list mailing list