Browse Source

Only convert eta to isoformat when it is not already a string (#4565)

* Fixed #4560.

* Added a test.

* Remove fake now...
Omer Katz 6 years ago
parent
commit
84da7802a3
3 changed files with 9 additions and 2 deletions
  1. 2 1
      celery/app/amqp.py
  2. 0 1
      t/integration/test_canvas.py
  3. 7 0
      t/unit/app/test_amqp.py

+ 2 - 1
celery/app/amqp.py

@@ -328,7 +328,8 @@ class AMQP(object):
             expires = maybe_make_aware(
                 now + timedelta(seconds=expires), tz=timezone,
             )
-        eta = eta and eta.isoformat()
+        if not isinstance(eta, string_t):
+            eta = eta and eta.isoformat()
         # If we retry a task `expires` will already be ISO8601-formatted.
         if not isinstance(expires, string_t):
             expires = expires and expires.isoformat()

+ 0 - 1
t/integration/test_canvas.py

@@ -165,7 +165,6 @@ class test_chain:
         result = c(delayed_sum.s(pause_time=0)).get()
         assert result == 3
 
-    @pytest.mark.xfail()
     def test_chain_error_handler_with_eta(self, manager):
         try:
             manager.app.backend.ensure_chords_allowed()

+ 7 - 0
t/unit/app/test_amqp.py

@@ -359,6 +359,13 @@ class test_as_task_v2:
         assert m.headers['expires'] == (
             now + timedelta(seconds=30)).isoformat()
 
+    def test_eta_to_datetime(self):
+        eta = datetime.utcnow()
+        m = self.app.amqp.as_task_v2(
+            uuid(), 'foo', eta=eta,
+        )
+        assert m.headers['eta'] == eta.isoformat()
+
     def test_callbacks_errbacks_chord(self):
 
         @self.app.task