Skip to content

Commit

Permalink
DH-4905 bug fix on csv file generation endpoint (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
DishenWang2023 authored and jcjc712 committed Nov 6, 2023
1 parent 0d1daee commit 9f78213
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 13 additions & 6 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,24 +372,32 @@ def get_response(self, response_id: str) -> Response:
@override
def get_response_file(self, response_id: str) -> JSONResponse:
response_repository = ResponseRepository(self.storage)

question_repository = QuestionRepository(self.storage)
db_connection_repository = DatabaseConnectionRepository(self.storage)
try:
result = response_repository.find_by_id(response_id)
question = question_repository.find_by_id(result.question_id)
db_connection = db_connection_repository.find_by_id(
question.db_connection_id
)
except InvalidId as e:
raise HTTPException(status_code=400, detail=str(e)) from e

if not result:
raise HTTPException(status_code=404, detail="Question not found")
raise HTTPException(
status_code=404, detail="Question, response, or db_connection not found"
)

s3 = S3()
return JSONResponse(
status_code=201,
content={
"csv_download_url": s3.download_url(result.csv_file_path),
"csv_download_url": s3.download_url(
result.csv_file_path, db_connection.file_storage
),
},
)


@override
def update_response(self, response_id: str) -> Response:
response_repository = ResponseRepository(self.storage)
Expand All @@ -415,7 +423,6 @@ def update_response(self, response_id: str) -> Response:
raise HTTPException(status_code=404, detail=str(e)) from e
return response


@override
def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
question_repository = QuestionRepository(self.storage)
Expand Down Expand Up @@ -488,7 +495,7 @@ def create_response(
context = context_store.retrieve_context_for_question(user_question)
start_generated_answer = time.time()
response = sql_generation.generate_response(
user_question, database_connection, context[0]
user_question, database_connection, context[0], large_query_result_in_csv
)
else:
response = Response(
Expand Down
4 changes: 3 additions & 1 deletion dataherald/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ def answer_question(
return self._api.answer_question_with_timeout(
run_evaluator, large_query_result_in_csv, question_request
)
return self._api.answer_question(run_evaluator, large_query_result_in_csv, question_request)
return self._api.answer_question(
run_evaluator, large_query_result_in_csv, question_request
)

def get_questions(self, db_connection_id: str | None = None) -> list[Question]:
return self._api.get_questions(db_connection_id)
Expand Down

0 comments on commit 9f78213

Please sign in to comment.