Skip to content

Commit

Permalink
feat: send failed query to request as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Oct 21, 2024
1 parent 2616bc6 commit 31f8287
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion agent/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def _sql(self, query: str, params=(), commit: bool = False, as_dict: bool = Fals
with self.db.atomic() as transaction:
try:
for q in queries:
self.last_executed_query = q
if not commit and self._is_restricted_query_for_no_commit_mode(q):
raise ProgrammingError("Provided query is not allowed in read only mode")
raise ProgrammingError(f"Provided query is not allowed in read only mode")

Check failure on line 101 in agent/database.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (F541)

agent/database.py:101:48: F541 f-string without any placeholders
output = None
row_count = None
cursor = self.db.execute_sql(q, params)
Expand Down
12 changes: 9 additions & 3 deletions agent/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,15 @@ def get_database_table_schemas(self):
return tables

def run_sql_query(self, query: str, commit: bool = False, as_dict: bool = False):
return Database(self.host, 3306, self.user, self.password, self.database).execute_query(
query, commit=commit, as_dict=as_dict
)
database = Database(self.host, 3306, self.user, self.password, self.database)
success, output = database.execute_query(query, commit=commit, as_dict=as_dict)
response = {
"success": success,
"data": output
}
if not success and hasattr(database, "last_executed_query"):
response["failed_query"] = database.last_executed_query
return response

@property
def job_record(self):
Expand Down
3 changes: 1 addition & 2 deletions agent/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ def run_sql(bench, site):
query = request.json.get("query")
commit = request.json.get("commit") or False
as_dict = request.json.get("as_dict") or False
success, data = Server().benches[bench].sites[site].run_sql_query(query, commit, as_dict)
return {"success": success, "data": data}
return Server().benches[bench].sites[site].run_sql_query(query, commit, as_dict)


@application.route(
Expand Down

0 comments on commit 31f8287

Please sign in to comment.