Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception when trying to add redundant file to graph #156

Open
CakeCrusher opened this issue Jan 9, 2025 · 0 comments
Open

Unhandled exception when trying to add redundant file to graph #156

CakeCrusher opened this issue Jan 9, 2025 · 0 comments

Comments

@CakeCrusher
Copy link

CakeCrusher commented Jan 9, 2025

(if you think this is solvable through the SDK alone (pretty sure that is the case), happy to contribute a PR, in that instance any guidance would be awesome)
To reproduce:

from writerai import Writer
from dotenv import load_dotenv
import os

load_dotenv()

WRITER_API_KEY = os.getenv("WRITER_API_KEY")
WRITER_APP_ID = os.getenv("WRITER_APP_ID")
if not WRITER_API_KEY or not WRITER_APP_ID:
    raise ValueError("missing env vars")

client = Writer(api_key=WRITER_API_KEY)

page = client.files.list(graph_id="5f19a...") # Graph containing a file
graph_id = page.data[0].graph_ids[0]
file_id = page.data[0].id

graph_file = client.graphs.add_file_to_graph(
    graph_id=graph_id,
    file_id=file_id
)

Error message:

---------------------------------------------------------------------------
InternalServerError                       Traceback (most recent call last)
Cell In[5], [line 18](vscode-notebook-cell:?execution_count=5&line=18)
     [15](vscode-notebook-cell:?execution_count=5&line=15) graph_id = page.data[0].graph_ids[0]
     [16](vscode-notebook-cell:?execution_count=5&line=16) file_id = page.data[0].id
---> [18](vscode-notebook-cell:?execution_count=5&line=18) graph_file = client.graphs.add_file_to_graph(
     [19](vscode-notebook-cell:?execution_count=5&line=19)     graph_id=graph_id,
     [20](vscode-notebook-cell:?execution_count=5&line=20)     file_id=file_id
     [21](vscode-notebook-cell:?execution_count=5&line=21) )

File c:\Notes\writer\.venv\lib\site-packages\writerai\resources\graphs.py:311, in GraphsResource.add_file_to_graph(self, graph_id, file_id, extra_headers, extra_query, extra_body, timeout)
    [309](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:309) if not graph_id:
    [310](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:310)     raise ValueError(f"Expected a non-empty value for `graph_id` but received {graph_id!r}")
--> [311](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:311) return self._post(
    [312](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:312)     f"/v1/graphs/{graph_id}/file",
    [313](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:313)     body=maybe_transform({"file_id": file_id}, graph_add_file_to_graph_params.GraphAddFileToGraphParams),
    [314](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:314)     options=make_request_options(
    [315](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:315)         extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
    [316](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:316)     ),
    [317](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:317)     cast_to=File,
    [318](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/resources/graphs.py:318) )

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1275, in SyncAPIClient.post(self, path, cast_to, body, options, files, binary_request, stream, stream_cls)
   [1255](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1255) def post(
   [1256](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1256)     self,
   [1257](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1257)     path: str,
   (...)
   [1265](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1265)     stream_cls: type[_StreamT] | None = None,
   [1266](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1266) ) -> ResponseT | _StreamT:
   [1267](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1267)     opts = FinalRequestOptions.construct(
   [1268](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1268)         method="post",
   [1269](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1269)         url=path,
   (...)
   [1273](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1273)         **options,
   [1274](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1274)     )
-> [1275](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1275)     return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:958, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
    [955](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:955) else:
    [956](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:956)     retries_taken = 0
--> [958](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:958) return self._request(
    [959](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:959)     cast_to=cast_to,
    [960](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:960)     options=options,
    [961](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:961)     stream=stream,
    [962](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:962)     stream_cls=stream_cls,
    [963](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:963)     retries_taken=retries_taken,
    [964](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:964) )

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1046, in SyncAPIClient._request(self, cast_to, options, retries_taken, stream, stream_cls)
   [1044](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1044) if remaining_retries > 0 and self._should_retry(err.response):
   [1045](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1045)     err.response.close()
-> [1046](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1046)     return self._retry_request(
   [1047](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1047)         input_options,
   [1048](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1048)         cast_to,
   [1049](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1049)         retries_taken=retries_taken,
   [1050](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1050)         response_headers=err.response.headers,
   [1051](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1051)         stream=stream,
   [1052](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1052)         stream_cls=stream_cls,
   [1053](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1053)     )
   [1055](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1055) # If the response is streamed then we need to explicitly read the response
   [1056](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1056) # to completion before attempting to access the response text.
   [1057](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1057) if not err.response.is_closed:

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1095, in SyncAPIClient._retry_request(self, options, cast_to, retries_taken, response_headers, stream, stream_cls)
   [1091](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1091) # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
   [1092](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1092) # different thread if necessary.
   [1093](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1093) time.sleep(timeout)
-> [1095](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1095) return self._request(
   [1096](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1096)     options=options,
   [1097](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1097)     cast_to=cast_to,
   [1098](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1098)     retries_taken=retries_taken + 1,
   [1099](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1099)     stream=stream,
   [1100](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1100)     stream_cls=stream_cls,
   [1101](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1101) )

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1046, in SyncAPIClient._request(self, cast_to, options, retries_taken, stream, stream_cls)
   [1044](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1044) if remaining_retries > 0 and self._should_retry(err.response):
   [1045](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1045)     err.response.close()
-> [1046](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1046)     return self._retry_request(
   [1047](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1047)         input_options,
   [1048](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1048)         cast_to,
   [1049](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1049)         retries_taken=retries_taken,
   [1050](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1050)         response_headers=err.response.headers,
   [1051](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1051)         stream=stream,
   [1052](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1052)         stream_cls=stream_cls,
   [1053](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1053)     )
   [1055](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1055) # If the response is streamed then we need to explicitly read the response
   [1056](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1056) # to completion before attempting to access the response text.
   [1057](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1057) if not err.response.is_closed:

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1095, in SyncAPIClient._retry_request(self, options, cast_to, retries_taken, response_headers, stream, stream_cls)
   [1091](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1091) # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
   [1092](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1092) # different thread if necessary.
   [1093](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1093) time.sleep(timeout)
-> [1095](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1095) return self._request(
   [1096](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1096)     options=options,
   [1097](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1097)     cast_to=cast_to,
   [1098](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1098)     retries_taken=retries_taken + 1,
   [1099](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1099)     stream=stream,
   [1100](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1100)     stream_cls=stream_cls,
   [1101](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1101) )

File c:\Notes\writer\.venv\lib\site-packages\writerai\_base_client.py:1061, in SyncAPIClient._request(self, cast_to, options, retries_taken, stream, stream_cls)
   [1058](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1058)         err.response.read()
   [1060](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1060)     log.debug("Re-raising status error")
-> [1061](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1061)     raise self._make_status_error_from_response(err.response) from None
   [1063](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1063) return self._process_response(
   [1064](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1064)     cast_to=cast_to,
   [1065](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1065)     options=options,
   (...)
   [1069](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1069)     retries_taken=retries_taken,
   [1070](file:///C:/Notes/writer/.venv/lib/site-packages/writerai/_base_client.py:1070) )

InternalServerError: Error code: 500 - {'tpe': 'fail.internal.generic', 'errors': [{'description': 'Unhandled exception', 'key': 'fail.internal.generic', 'extras': None}], 'extras': None}

(note i was not able to test adding an actual new file because of #155 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant