CD2 Python Client Library Typing Error

Jump to solution
AlexJackson
Community Explorer

I recently (18 March 2025) started getting a typing error when fetching jobs from snapshot queries using the python client library. I haven't changed anything since I started getting this error, so I'm inclined to believe there is an issue with the typing logic. This is my stacktrace:

File "/Users/asj18a/code/snowflake-extract-load/CanvasSrc/CanvasDataInteraction.py", line 387, in run_job
    job = await session.query_snapshot(
                │       └ <function DAPSession.query_snapshot at 0x128518860>
                └ <dap.api.DAPSession object at 0x1285d7110>

  File "/Users/asj18a/code/snowflake-extract-load/.venv/lib/python3.11/site-packages/dap/api.py", line 393, in query_snapshot
    job = await self._post(f"/dap/query/{namespace}/table/{table}/data", query, Job)  # type: ignore
                │    │                                                   │      └ typing.Union[dap.dap_types.TableJob, dap.dap_types.CompleteSnapshotJob, dap.dap_types.CompleteIncrementalJob, dap.dap_types.F...
                │    │                                                   └ SnapshotQuery(format=<Format.Parquet: 'parquet'>, mode=None)
                │    └ <function DAPSession._post at 0x1285185e0>
                └ <dap.api.DAPSession object at 0x1285d7110>
  File "/Users/asj18a/code/snowflake-extract-load/.venv/lib/python3.11/site-packages/dap/api.py", line 311, in _post
    return await self._process(response, response_type)
                 │    │        │         └ typing.Union[dap.dap_types.TableJob, dap.dap_types.CompleteSnapshotJob, dap.dap_types.CompleteIncrementalJob, dap.dap_types.F...
                 │    │        └ <ClientResponse(https://api-gateway.instructure.com/dap/query/canvas/table/grading_period_groups/data) [200 OK]>
                 │    │          <CIMultiDict...
                 │    └ <function DAPSession._process at 0x128518720>
                 └ <dap.api.DAPSession object at 0x1285d7110>
  File "/Users/asj18a/code/snowflake-extract-load/.venv/lib/python3.11/site-packages/dap/api.py", line 360, in _process
    response_object = json_to_object(response_type, response_payload)
                      │              │              └ {'id': 'b9ea26b4-2d95-49ae-b9da-80b23d399236', 'status': 'complete', 'objects': [{'id': 'b9ea26b4-2d95-49ae-b9da-80b23d399236...
                      │              └ typing.Union[dap.dap_types.TableJob, dap.dap_types.CompleteSnapshotJob, dap.dap_types.CompleteIncrementalJob, dap.dap_types.F...
                      └ <function json_to_object at 0x128026b60>
  File "/Users/asj18a/code/snowflake-extract-load/.venv/lib/python3.11/site-packages/strong_typing/serialization.py", line 76, in json_to_object
    return parser.parse(data)
           │      │     └ {'id': 'b9ea26b4-2d95-49ae-b9da-80b23d399236', 'status': 'complete', 'objects': [{'id': 'b9ea26b4-2d95-49ae-b9da-80b23d399236...
           │      └ <function UnionDeserializer.parse at 0x12806eb60>
           └ <strong_typing.deserializer.UnionDeserializer object at 0x128746250>
  File "/Users/asj18a/code/snowflake-extract-load/.venv/lib/python3.11/site-packages/strong_typing/deserializer.py", line 389, in parse
    raise JsonKeyError(
          └ <class 'strong_typing.exception.JsonKeyError'>

strong_typing.exception.JsonKeyError: type `Union[TableJob, CompleteSnapshotJob, CompleteIncrementalJob, FailedJob]` could not be instantiated from: {'id': 'b9ea26b4-2d95-49ae-b9da-80b23d399236', 'status': 'complete', 'objects': [{'id':
'b9ea26b4-2d95-49ae-b9da-80b23d399236/part-00000-be049ff3-6f89-4e7b-9b10-c9d5562d7942-c000.gz.parquet'}], 'expires_at': '2025-03-19T18:46:33Z', 'at': '2025-03-18T15:10:19Z'}

 As you can see, the job is successfully created, things seem to be working in the back end, but the logic to parse a CompleteSnapshotJob from the successful JSON payload is failing. This occurs with the conversion to both CompleteSnapshotJob and CompleteIncrementalJob. If there is anything else y'all need from me, please let me know.

0 Likes
1 Solution