smartsheet-platform / smartsheet-python-sdk

Library that uses Python to connect to Smartsheet services (using API 2.0).
Apache License 2.0
136 stars 81 forks source link

2.105.1 updates #155

Closed timwellswa closed 4 years ago

timwellswa commented 4 years ago

fix: don't add time offset to date types when serializing

timwellswa commented 4 years ago

This MR addresses an issue where we are unable to update non_working_days in project_settings.

This code fails:

result = smartsheet_client.Sheets.get_sheet(2823965107349380)
result = smartsheet_client.Sheets.update_sheet(
    sheet_id,
    smartsheet.models.Sheet({
        'project_settings': smartsheet.models.ProjectSettings({
            'non_working_days': ['2020-10-30', '2020-12-23']
        })
    })
)

Log information as follows:

DEBUG:smartsheet.smartsheet:{"requestBody": {"projectSettings": {"nonWorkingDays": ["2020-10-30Z", "2020-12-23Z"]}}}
ERROR:smartsheet.smartsheet:{"response": {"statusCode": 400, "reason": "Bad Request", "content": {"errorCode": 1008, "message": "Unable to parse request. The following error occurred: Field \"null\" was of unexpected type.", "refId": "1v6dka207auqj"}}}
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2019.2\plugins\python\helpers\pydev\pydevd.py", line 1434, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2019.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Smartsheet/smartsheet-python-sample/sample.py", line 237, in <module>
    'non_working_days': ['2020-10-30', '2020-12-23']
  File "D:\Smartsheet\smartsheet-python-sdk\smartsheet\sheets.py", line 1117, in update_sheet
    response = self._base.request(prepped_request, expected, _op)
  File "D:\Smartsheet\smartsheet-python-sdk\smartsheet\smartsheet.py", line 250, in request
    raise the_ex(native, str(native.result.code) + ': ' + native.result.message)
smartsheet.exceptions.ApiError: {"result": {"code": 1008, "errorCode": 1008, "message": "Unable to parse request. The following error occurred: Field \"null\" was of unexpected type.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "1v6dka207auqj", "shouldRetry": false, "statusCode": 400}}

In the JSON body, notice the the date fields are followed by the Z timezone offset.

Luckily date is only used for non-working days in the SDK, so the fix and testing for it are pretty localized.