Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Added env setting for django atomic requests (#664)

Rahul Johny469617e31a79
diff --git a/backend/account/authentication_controller.py b/backend/account/authentication_controller.py
index f8b41e921..38edce514 100644
--- a/backend/account/authentication_controller.py
+++ b/backend/account/authentication_controller.py
@@ -35,6 +35,7 @@ from account.serializer import (
from account.user import UserService
from django.conf import settings
from django.contrib.auth import logout as django_logout
+from django.db import transaction
from django.db.utils import IntegrityError
from django.middleware import csrf
from django.shortcuts import redirect
@@ -165,28 +166,33 @@ class AuthenticationController:
organization = OrganizationService.get_organization_by_org_id(
organization_id
)
- if not organization:
- try:
- organization_data: OrganizationData = (
- self.auth_service.get_organization_by_org_id(organization_id)
- )
- except ValueError:
- raise OrganizationNotExist()
- try:
- organization = OrganizationService.create_organization(
- organization_data.name,
- organization_data.display_name,
- organization_data.id,
- )
- new_organization = True
- except IntegrityError:
- raise DuplicateData(
- f"{ErrorMessage.ORGANIZATION_EXIST}, \
- {ErrorMessage.DUPLICATE_API}"
- )
- organization_member = self.create_tenant_user(
- organization=organization, user=user
- )
+
+ # Django tenant migration will happen in the below code block
+ with transaction.atomic(durable=True):
+ if not organization:
+ try:
+ organization_data: OrganizationData = (
+ self.auth_service.get_organization_by_org_id(
+ organization_id
+ )
+ )
+ except ValueError:
+ raise OrganizationNotExist()
+ try:
+ organization = OrganizationService.create_organization(
+ organization_data.name,
+ organization_data.display_name,
+ organization_data.id,
+ )
+ new_organization = True
+ except IntegrityError:
+ raise DuplicateData(
+ f"{ErrorMessage.ORGANIZATION_EXIST}, \
+ {ErrorMessage.DUPLICATE_API}"
+ )
+ organization_member = self.create_tenant_user(
+ organization=organization, user=user
+ )
if new_organization:
try:
diff --git a/backend/backend/settings/base.py b/backend/backend/settings/base.py
index a4580c43b..753aaa71e 100644
--- a/backend/backend/settings/base.py
+++ b/backend/backend/settings/base.py
@@ -361,7 +361,7 @@ TEMPLATES = [
WSGI_APPLICATION = "backend.wsgi.application"
-
+ATOMIC_REQUESTS = os.environ.get("DJANGO_ATOMIC_REQUESTS", False)
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
@@ -373,7 +373,7 @@ DATABASES = {
"HOST": f"{DB_HOST}",
"PASSWORD": f"{DB_PASSWORD}",
"PORT": f"{DB_PORT}",
- "ATOMIC_REQUESTS": True,
+ "ATOMIC_REQUESTS": ATOMIC_REQUESTS,
}
}
diff --git a/backend/prompt_studio/prompt_studio_core/urls.py b/backend/prompt_studio/prompt_studio_core/urls.py
index 0abc1c436..3a32f63c4 100644
--- a/backend/prompt_studio/prompt_studio_core/urls.py
+++ b/backend/prompt_studio/prompt_studio_core/urls.py
@@ -1,6 +1,4 @@
-from django.db import transaction
from django.urls import path
-from django.utils.decorators import method_decorator
from rest_framework.urlpatterns import format_suffix_patterns
from .views import PromptStudioCoreView
@@ -79,9 +77,7 @@ urlpatterns = format_suffix_patterns(
),
path(
"prompt-studio/index-document/<uuid:pk>",
- method_decorator(transaction.non_atomic_requests)(
- prompt_studio_prompt_index
- ),
+ prompt_studio_prompt_index,
name="prompt-studio-prompt-index",
),
path(