diff --git a/daras_ai_v2/glossary.py b/daras_ai_v2/glossary.py index 0c1610250..ae513b042 100644 --- a/daras_ai_v2/glossary.py +++ b/daras_ai_v2/glossary.py @@ -1,7 +1,8 @@ import gooey_ui as st from daras_ai_v2.redis_cache import redis_cache_decorator from contextlib import contextmanager -from glossary_resources.models import GlossaryResources, AsyncAtomic +from glossary_resources.models import GlossaryResources +from django.db import transaction DEFAULT_GLOSSARY_URL = "https://docs.google.com/spreadsheets/d/1IRHKcOC86oZXwMB0hR7eej7YVg5kUHpriZymwYQcQX4/edit?usp=sharing" # only viewing access PROJECT_ID = "dara-c1b52" # GCP project id @@ -43,7 +44,7 @@ def glossary_resource(f_url: str = DEFAULT_GLOSSARY_URL): return # I could not get this to work with concurrent translate requests without locking everything :( - with AsyncAtomic(): + with transaction.atomic(): resource, created = GlossaryResources.objects.select_for_update().get_or_create( f_url=f_url ) diff --git a/glossary_resources/models.py b/glossary_resources/models.py index f714dcced..4237e5b82 100644 --- a/glossary_resources/models.py +++ b/glossary_resources/models.py @@ -1,4 +1,4 @@ -from django.db import models, transaction +from django.db import models from bots.custom_fields import CustomURLField import uuid from asgiref.sync import sync_to_async @@ -15,15 +15,3 @@ class Meta: def get_clean_name(self): return str(self.glossary_name).lower() - - -class AsyncAtomic(transaction.Atomic): - def __init__(self, using=None, savepoint=True, durable=False): - super().__init__(using, savepoint, durable) - - async def __aenter__(self): - await sync_to_async(super().__enter__)() - return self - - async def __aexit__(self, exc_type, exc_value, traceback): - await sync_to_async(super().__exit__)(exc_type, exc_value, traceback)