fix: a busy Tiny retries the whole delivery instead of sending the order without its seller
Some checks failed
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-27 12:33:39 -03:00
parent b027bb5013
commit 6a8855504f
2 changed files with 12 additions and 1 deletions

View File

@@ -873,6 +873,9 @@ class TinyOrders:
failed reading leaves the order without one: it must still go."""
try:
seller = (self.request('GET', f'/contatos/{contact_id}').get('vendedor') or {}).get('id')
except TinyRateLimit:
# Busy for a moment: the whole delivery is tried again, the seller with it.
raise
except TinyError as exc:
logging.warning('Tiny: could not read the seller of contact %s: %s', contact_id, exc)
return None

View File

@@ -77,7 +77,7 @@ class FakeTinyCase(unittest.TestCase):
if request.method == 'GET' and path.startswith('/contatos/'):
wanted = int(path.rsplit('/', 1)[-1])
if self.refuse_contact:
return httpx.Response(503, text='indisponível')
return httpx.Response(429 if self.refuse_contact == 429 else 503, text='indisponível')
return httpx.Response(200, json=next(c for c in self.contacts if c['id'] == wanted))
if request.method == 'POST' and path == '/contatos':
contact = {**json.loads(request.content), 'id': 500 + len(self.contacts)}
@@ -273,6 +273,14 @@ class TinyTests(FakeTinyCase):
self.assertEqual(self.tiny.deliver('k1', PAID)['status'], 'created')
self.assertNotIn('vendedor', self.orders[0])
def test_a_busy_tiny_retries_the_delivery_instead_of_dropping_the_seller(self):
from app.tiny import TinyRateLimit
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477}})
self.refuse_contact = 429
with self.assertRaises(TinyRateLimit):
self.tiny.deliver('k1', PAID)
self.assertEqual(self.orders, [])
def test_a_contact_typed_without_punctuation_is_found_too(self):
self.contacts.append({'id': 322, 'cpfCnpj': '11222333000181'})
self.tiny.deliver('k1', PAID)