msgraph-sdk-python icon indicating copy to clipboard operation
msgraph-sdk-python copied to clipboard

AddPostRequestBody does not contain the values parameter anymore

Open kyjovskym opened this issue 1 year ago • 1 comments

Describe the bug

According to the documentation pages:

  • https://learn.microsoft.com/en-us/graph/api/table-post-rows?view=graph-rest-1.0&tabs=python
  • https://learn.microsoft.com/en-us/graph/api/tablerowcollection-add?view=graph-rest-1.0&tabs=python

there should be an option in the initialization of WorkbookTableRow and AddPostRequestBody to specify the values attribute. However, the construction of these objects ends with the following exception:

TypeError: WorkbookTableRow.__init__() got an unexpected keyword argument 'values'

This behavior disallows updating Excel using MS Graphs.

Expected behavior

When creating WorkbookTableRow or AddPostRequestBody with the values parameter, the object should be created, and the POST to the underlying Excel table should be successful.

How to reproduce

Follow the instructions on your documentation pages:

  • https://learn.microsoft.com/en-us/graph/api/table-post-rows?view=graph-rest-1.0&tabs=python
  • https://learn.microsoft.com/en-us/graph/api/tablerowcollection-add?view=graph-rest-1.0&tabs=python

SDK Version

1.12.0

Latest version known to work for scenario above?

No response

Known Workarounds

Use CLI

Debug output

Click to expand log ```

Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/plugins/python/helpers-pro/pydevd_asyncio/pydevd_nest_asyncio.py", line 138, in run return loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Applications/PyCharm.app/Contents/plugins/python/helpers-pro/pydevd_asyncio/pydevd_nest_asyncio.py", line 243, in run_until_complete return f.result() ^^^^^^^^^^ File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/futures.py", line 203, in result raise self._exception.with_traceback(self._exception_tb) File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 277, in __step result = coro.send(None) ^^^^^^^^^^^^^^^ File "/Users/michalkyjovsky/Dev/Work/litfin/orpea/orpea-client-to-excel-worker/sharepoint.py", line 82, in add_record post_body = WorkbookTableRow(values=sanitized_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: WorkbookTableRow.init() got an unexpected keyword argument 'values'

</details>


### Configuration

- Chip: Apple M1 Pro
- OS: macOS Sequoia 15.1
- Architecture: ARM64
- To my knowledge, the issue is not specific to the configuration.

### Other information

_No response_

kyjovskym avatar Nov 19 '24 01:11 kyjovskym

Encountered the same issue when adding rows. msgraph is apparently not prepared to serialize lists containing lists. Managed to work around by manually serializing the body.

add = table client.drives.by_drive_id(DRIVE_ID).items.by_drive_item_id(ITEM_ID).workbook.worksheets.by_workbook_worksheet_id(WORKSHEET_ID).tables.by_workbook_table_id(TABLE_ID).rows.add
request_info = kiota_abstractions.request_information.RequestInformation(kiota_abstractions.method.Method.POST, add.url_template, add.path_parameters)
request_info.headers.try_add("Accept", "application/json")
request_info.content = (str.encode(json.dumps(dict(values=LIST_OF_LISTS))))

await add.request_adapter.send_async(request_info, msgraph.generated.models.workbook_table_row.WorkbookTableRow, {'XXX': msgraph.generated.models.o_data_errors.o_data_error.ODataError})

Works as expected. This is reversed engineered by following the row.add.post method.

ptrba avatar Feb 01 '25 18:02 ptrba