Skip to content

Commit 59c0386

Browse files
abhizipstackclaude
andcommitted
fix: address Greptile P1s — CLI-safe timezone import + DB connection leak
P1: `from django.utils import timezone` at module level crashes when visitran is used as a standalone CLI without Django installed. Wrapped in try/except with a minimal fallback that provides timezone.now() via stdlib datetime. P1: close_db_connection() was only called in the success path of execute_run_command. On exception the connection leaked. Moved to a finally block so it always runs regardless of outcome. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3889e26 commit 59c0386

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

backend/backend/core/routers/execute/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def execute_run_command(request: Request, project_id: str) -> Response:
5959
app = ApplicationContext(project_id=project_id)
6060
try:
6161
app.execute_visitran_run_command(current_model=file_name, environment_id=environment_id)
62-
app.visitran_context.close_db_connection()
6362
app.backup_current_no_code_model()
6463
logger.info(f"[execute_run_command] Completed successfully for file_name={file_name}")
6564
_data = {"status": "success"}
@@ -68,6 +67,8 @@ def execute_run_command(request: Request, project_id: str) -> Response:
6867
logger.exception(f"[execute_run_command] DAG execution failed for file_name={file_name}")
6968
_data = {"status": "failed", "error_message": "Model execution failed. Check server logs for details."}
7069
return Response(data=_data, status=status.HTTP_400_BAD_REQUEST)
70+
finally:
71+
app.visitran_context.close_db_connection()
7172

7273

7374

backend/visitran/visitran.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import ibis
1818
import networkx as nx
19-
from django.utils import timezone
19+
try:
20+
from django.utils import timezone
21+
except ImportError:
22+
from datetime import datetime, timezone as _tz
23+
24+
class timezone:
25+
@staticmethod
26+
def now():
27+
return datetime.now(_tz.utc)
2028
from visitran import utils
2129
from visitran.adapters.adapter import BaseAdapter
2230
from visitran.adapters.seed import BaseSeed

0 commit comments

Comments
 (0)