Shopify / Shopify/shopify-app-python

int(retry_after) raises ValueError on a non-integer Retry-After value

Abierto Apto para principiantes
#18 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

devtools-gardener
Lenguaje dominante
Python
Estrellas
17
Forks
1
Merge medio
3 min
PR fusionados (30 d)
2

Descripción

Summary

The 429 retry handlers in admin_graphql_request coerce Retry-After with int(), which raises ValueError on any value that is not a bare integer. HTTP permits a decimal seconds value as well as an HTTP-date, and decimal values are what Shopify's own rate-limited REST responses carry.

The exception is uncaught, so it propagates out of admin_graphql_request instead of being retried or returned as a GQLResult.

Version: shopifyapp 1.0.1 (sdist from PyPI).

Cause

shopify_app/graphql/admin_graphql.py:398 (sync):

time.sleep(int(retry_after))

and shopify_app/graphql/admin_graphql.py:454 (async):

await asyncio.sleep(int(retry_after))

Reproduction

>>> int("2.0")
Traceback (most recent call last):
  ...
ValueError: invalid literal for int() with base 10: '2.0'

Currently masked

This is not reachable today, because the header is never actually read: response_headers.get("Retry-After", "1") always returns its "1" default, for the reason described in #17.

That coupling is the reason this is worth filing on its own — repairing the header lookup alone turns a silent bug into an uncaught exception. The two are best addressed together.

Suggested fix

Parse defensively and fall back rather than raising:

try:
    delay = float(retry_after)
except (TypeError, ValueError):
    delay = 1.0
time.sleep(delay)

float() accepts the integer form as well, so it covers both spellings. If HTTP-date support is wanted, email.utils.parsedate_to_datetime handles that form.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en shopify_app/graphql/admin_graphql.py, en los manejadores de reintento síncrono y asíncrono de admin_graphql_request alrededor de las líneas 398 y 454. Rastrea cómo se obtiene Retry-After y, a continuación, verifica que los valores decimales o no válidos ya no escapen como ValueError y que ambos manejadores continúen con su comportamiento de reintento o GQLResult.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api, backend
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
78/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.