Skip to content

Commit 9f6f9d4

Browse files
Merge pull request #305 from microsoft/psl-codeq
fix: Improve code quality
2 parents 1aa2ab0 + 72e0dc5 commit 9f6f9d4

20 files changed

Lines changed: 24 additions & 150 deletions

File tree

src/backend/api/api_routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ async def batch_status_updates(
279279
try:
280280
await websocket.receive_text()
281281
except asyncio.TimeoutError:
282+
# TimeoutError is ignored to keep the WebSocket connection open without receiving data
282283
pass
283284

284285
except WebSocketDisconnect:

src/backend/common/database/cosmosdb.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ async def update_batch_entry(
352352
batch["file_count"] = file_count
353353

354354
await self.batch_container.replace_item(item=batch_id, body=batch)
355-
# if isinstance(status, ProcessStatus):
356-
# self.logger.info(f"Updated batch {batch_id} to status {status.value}")
357-
# else:
358-
# self.logger.info(f"Updated batch {batch_id} to status {status}")
359355

360356
return batch
361357
except Exception as e:

src/backend/common/services/batch_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ async def delete_batch(self, batch_id: UUID, user_id: str):
175175

176176
self.logger.info(f"Successfully deleted batch with ID: {batch_id}")
177177
return {"message": "Batch deleted successfully", "batch_id": str(batch_id)}
178+
else:
179+
return {"message": "Batch not found", "batch_id": str(batch_id)}
178180

179181
async def delete_file(self, file_id: UUID, user_id: str):
180182
"""Delete a file and its logs, and update batch file count."""

src/backend/common/storage/blob_azure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def upload_file(
5252
raise
5353
try:
5454
# Upload the file
55-
upload_results = blob_client.upload_blob( # noqa: F841
55+
blob_client.upload_blob(
5656
file_content,
5757
content_type=content_type,
5858
metadata=metadata,

src/backend/sql_agents/helpers/comms_manager.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,3 @@ async def cleanup(self):
270270

271271
except Exception as e:
272272
self.logger.error("Error during cleanup: %s", str(e))
273-
274-
def __del__(self):
275-
"""Destructor to ensure cleanup if not explicitly called."""
276-
try:
277-
# Only attempt cleanup if there's an active event loop
278-
loop = asyncio.get_running_loop()
279-
if loop and not loop.is_closed():
280-
# Schedule cleanup as a task
281-
loop.create_task(self.cleanup())
282-
except RuntimeError:
283-
# No event loop running, can't clean up asynchronously
284-
self.logger.warning("No event loop available for cleanup in destructor")
285-
except Exception as e:
286-
self.logger.error("Error in destructor cleanup: %s", str(e))

src/backend/sql_agents/tools/src/Program.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using Microsoft.SqlServer.TransactSql.ScriptDom;
56
using Newtonsoft.Json;
67

@@ -42,18 +43,14 @@ static void Main(string[] args)
4243

4344
IList<ParseError> errors = ParseSqlQuery(sqlQuery);
4445

45-
var errorList = new List<Dictionary<string, object>>();
46-
47-
foreach (var error in errors)
48-
{
49-
var errorDict = new Dictionary<string, object>
46+
var errorList = errors
47+
.Select(error => new Dictionary<string, object>
5048
{
5149
{ "Line", error.Line },
5250
{ "Column", error.Column },
5351
{ "Error", error.Message }
54-
};
55-
errorList.Add(errorDict);
56-
}
52+
})
53+
.ToList();
5754

5855
string jsonOutput = JsonConvert.SerializeObject(errorList, Formatting.Indented);
5956
Console.WriteLine(jsonOutput);

src/frontend/frontend_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dotenv import load_dotenv
55
from fastapi import FastAPI
66
from fastapi.middleware.cors import CORSMiddleware
7-
from fastapi.responses import FileResponse, HTMLResponse
7+
from fastapi.responses import FileResponse
88
from fastapi.staticfiles import StaticFiles
99

1010
# Load environment variables from .env file

src/frontend/src/api/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export const renderErrorSection = (batchSummary, expandedSections, setExpandedSe
414414

415415
export const renderErrorContent = (batchSummary) => {
416416
// Group errors by file
417-
const errorFiles = batchSummary.files.filter(file => file.error_count && file.error_count);
417+
const errorFiles = batchSummary.files.filter(file => file.error_count);
418418
if (errorFiles.length === 0) {
419419
return (
420420
<div className={useStyles().errorItem}>

src/frontend/src/components/batchHistoryPanel.tsx

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect, useRef } from "react";
22

3-
import { useDispatch, useSelector } from 'react-redux';
3+
import { useDispatch } from 'react-redux';
44
import { Card, Spinner, Tooltip } from "@fluentui/react-components";
55
import { useNavigate } from "react-router-dom";
66
import ConfirmationDialog from "../commonComponents/ConfirmationDialog/confirmationDialogue";
@@ -21,7 +21,7 @@ interface BatchHistoryItem {
2121
status: string;
2222
}
2323
const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
24-
const headers = {}
24+
const headers = {};
2525
const [batchHistory, setBatchHistory] = useState<BatchHistoryItem[]>([]);
2626
const [loading, setLoading] = useState(false);
2727
const [error, setError] = useState<string | null>(null);
@@ -81,46 +81,6 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
8181
}
8282
};
8383

84-
// Function to categorize batches
85-
const categorizeBatches = () => {
86-
const now = new Date();
87-
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
88-
89-
// Get start of "Today", "Past 7 days", and "Past 30 days" in LOCAL time
90-
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
91-
const past7DaysStart = new Date(todayStart);
92-
const past30DaysStart = new Date(todayStart);
93-
94-
past7DaysStart.setDate(todayStart.getDate() - 7);
95-
past30DaysStart.setDate(todayStart.getDate() - 30);
96-
97-
const todayBatches: BatchHistoryItem[] = [];
98-
const past7DaysBatches: BatchHistoryItem[] = [];
99-
const past30DaysBatches: BatchHistoryItem[] = [];
100-
101-
batchHistory.forEach(batch => {
102-
// Convert UTC timestamp to user's local date
103-
const updatedAtUTC = new Date(batch.created_at);
104-
const updatedAtLocal = new Date(updatedAtUTC.toLocaleString("en-US", { timeZone: userTimeZone }));
105-
106-
// Extract only the local **date** part for comparison
107-
const updatedDate = new Date(updatedAtLocal.getFullYear(), updatedAtLocal.getMonth(), updatedAtLocal.getDate());
108-
109-
// Categorize based on **exact day comparison**
110-
if (updatedDate.getTime() === todayStart.getTime()) {
111-
todayBatches.push(batch);
112-
} else if (updatedDate.getTime() >= past7DaysStart.getTime()) {
113-
past7DaysBatches.push(batch);
114-
} else if (updatedDate.getTime() >= past30DaysStart.getTime()) {
115-
past30DaysBatches.push(batch);
116-
}
117-
});
118-
119-
return { todayBatches, past7DaysBatches, past30DaysBatches };
120-
};
121-
122-
// const { todayBatches, past7DaysBatches, past30DaysBatches } = categorizeBatches();
123-
12484
const deleteBatchFromHistory = (batchId: string) => {
12585
// Get the current URL path
12686
const currentPath = window.location.pathname;

src/frontend/src/components/bottomBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Button, Card, Dropdown, DropdownProps, Option } from "@fluentui/react-components"
2-
import React, { useState } from "react"
3-
import { useNavigate } from "react-router-dom"
2+
import React from "react"
43

54
// Define possible upload states
65
const UploadState = {

0 commit comments

Comments
 (0)