ResourceExhausted

django Exception Published at March 11, 2025, 12:19 a.m. by admin@senrigan.org

ResourceExhaustedで無限ループ

@receiver(post_save, sender=Flashcard)
def save_audio(sender, instance, created, **kewargs):
    if created:
        client = texttospeech.TextToSpeechClient()
        synthesis_input = texttospeech.SynthesisInput(text=instance.title)
...
        instance.audio.save(audio_path, audio_file)
        instance.save()

if created:を削除するとinstance.save()した後にまたsave_audio()が呼ばれて無限ループに陥ってResourceExhausted発生。GoogleのAPIにアタックしてしまったらしい。rate limitとかあるから多くのリクエストは弾かれてるだろうけど、やったらダメなやつだねこれは。すみません。

ResourceExhausted at /admin/tango/flashcard/94/change/
429 Resource has been exhausted (e.g. check quota).
Request Method: POST
Request URL:    http://127.0.0.1:8000/admin/tango/flashcard/94/change/
Django Version: 5.1.6
Exception Type: ResourceExhausted
Exception Value:    
429 Resource has been exhausted (e.g. check quota).
Exception Location: /workspace/senrigan/.venv/lib/python3.12/site-packages/google/api_core/grpc_helpers.py, line 78, in error_remapped_callable
Raised during:  django.contrib.admin.options.change_view