Skip to content

Commit e0b1799

Browse files
Merge pull request #1944 from kili-technology/feature/lab-3842-aa-sdk-user-when-i-have-a-fail-in-lock-i-can-see-the-reason
feat: aa sdk user when i have a fail in lock i can see the reason
2 parents fcb6370 + 5dc1fed commit e0b1799

File tree

7 files changed

+49
-435
lines changed

7 files changed

+49
-435
lines changed

src/kili/adapters/kili_api_gateway/issue/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def create_issues(
4141
payload = {
4242
"issues": [
4343
{
44-
"issueNumber": 0,
4544
"labelID": issue.label_id,
4645
"objectMid": issue.object_mid,
4746
"type": type_,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Helper functions to extract context from GraphQL error messages."""
2+
import ast
3+
from typing import Dict, Optional
4+
5+
6+
def extract_error_context(message: str) -> Optional[Dict[str, str]]:
7+
"""Parse the string error message to extract the first context information."""
8+
try:
9+
parsed_errors = ast.literal_eval(message)
10+
return parsed_errors[0].get("extensions").get("context")
11+
except (SyntaxError, ValueError):
12+
return None

src/kili/core/graphql/graphql_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from kili.adapters.http_client import HttpClient
3434
from kili.core.constants import MAX_CALLS_PER_MINUTE
3535
from kili.core.graphql.clientnames import GraphQLClientName
36+
from kili.core.graphql.exceptions import extract_error_context
3637
from kili.utils.logcontext import LogContext
3738

3839
gql_requests_logger.setLevel(logging.WARNING)
@@ -281,8 +282,8 @@ def execute(
281282
raise kili.exceptions.GraphQLError(error=err.errors) from err
282283

283284
except exceptions.TransportQueryError as err: # remove validation error
284-
# the server refused the query after some retries, we crash
285-
raise kili.exceptions.GraphQLError(error=err.errors) from err
285+
context = extract_error_context(str(err.errors))
286+
raise kili.exceptions.GraphQLError(error=err.errors, context=context) from err
286287

287288
@retry(
288289
reraise=True, # re-raise the last exception

src/kili/entrypoints/mutations/issue/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def append_to_issues(
7373
variables = {
7474
"issues": [
7575
{
76-
"issueNumber": 0,
7776
"labelID": label_id,
7877
"objectMid": object_mid,
7978
"type": type_,

src/kili/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
class GraphQLError(Exception):
77
"""Raised when the GraphQL call returns an error."""
88

9-
def __init__(self, error, batch_number=None) -> None:
9+
def __init__(self, error, batch_number=None, context=None) -> None:
1010
self.error = error
11+
self.context = context
1112

1213
if isinstance(error, List):
1314
error = error[0]

0 commit comments

Comments
 (0)