Repository: googleapis/python-api-core
Pull request #164 (2021-03-30 16:03:34)

Fix retry.with_delay multiplier parameter handling
Issue: https://github.com/googleapis/python-api-core/issues/163

google-cla[bot]: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-api-core%2Fpull%2F164) for more info**.

<!-- need_sender_cla -->
quentin-sommer: @googlebot I signed it!
google-cla[bot]: We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors.  If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA ([login here](https://cla.developers.google.com/) to double check)?  If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment `@googlebot I fixed it.`. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-api-core%2Fpull%2F164) for more info**.

<!-- need_author_cla -->
quentin-sommer: @googlebot I fixed it
quentin-sommer: @busunkim96 done. I also took the liberty of updating `test_with_delay` because it was mutating the object using the same new values ([Commit](https://github.com/googleapis/python-api-core/pull/164/commits/d3efb76a1367a2577f00d7eb07fc5fc2ad13d46f))

Patch:
diff --git a/google/api_core/retry.py b/google/api_core/retry.py
index 592d34f..43e4f07 100644
--- a/google/api_core/retry.py
+++ b/google/api_core/retry.py
@@ -345,7 +345,7 @@ class Retry(object):
             predicate=self._predicate,
             initial=initial if initial is not None else self._initial,
             maximum=maximum if maximum is not None else self._maximum,
-            multiplier=multiplier if maximum is not None else self._multiplier,
+            multiplier=multiplier if multiplier is not None else self._multiplier,
             deadline=self._deadline,
             on_error=self._on_error,
         )


Test patch:
diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py
index a0160e9..4c2e457 100644
--- a/tests/unit/test_retry.py
+++ b/tests/unit/test_retry.py
@@ -246,12 +246,44 @@ class TestRetry(object):
             deadline=4,
             on_error=mock.sentinel.on_error,
         )
-        new_retry = retry_.with_delay(initial=1, maximum=2, multiplier=3)
+        new_retry = retry_.with_delay(initial=5, maximum=6, multiplier=7)
         assert retry_ is not new_retry
-        assert new_retry._initial == 1
+        assert new_retry._initial == 5
+        assert new_retry._maximum == 6
+        assert new_retry._multiplier == 7
+
+        # the rest of the attributes should remain the same
+        assert new_retry._deadline == retry_._deadline
+        assert new_retry._predicate is retry_._predicate
+        assert new_retry._on_error is retry_._on_error
+
+    def test_with_delay_partial_options(self):
+        retry_ = retry.Retry(
+            predicate=mock.sentinel.predicate,
+            initial=1,
+            maximum=2,
+            multiplier=3,
+            deadline=4,
+            on_error=mock.sentinel.on_error,
+        )
+        new_retry = retry_.with_delay(initial=4)
+        assert retry_ is not new_retry
+        assert new_retry._initial == 4
         assert new_retry._maximum == 2
         assert new_retry._multiplier == 3
 
+        new_retry = retry_.with_delay(maximum=4)
+        assert retry_ is not new_retry
+        assert new_retry._initial == 1
+        assert new_retry._maximum == 4
+        assert new_retry._multiplier == 3
+
+        new_retry = retry_.with_delay(multiplier=4)
+        assert retry_ is not new_retry
+        assert new_retry._initial == 1
+        assert new_retry._maximum == 2
+        assert new_retry._multiplier == 4
+
         # the rest of the attributes should remain the same
         assert new_retry._deadline == retry_._deadline
         assert new_retry._predicate is retry_._predicate