In certain situations, when passing subsclasses of str as parameters, there are not recognized as strings and incorrectly encoded in a query.
Specifically, I stumbled over this problem when passing a enum.StrEnum to the office365.sharepoint.lists.collections.ListCollection.get_by_id() method. The resulting error resembles this (note the missing single quotes around the GUID):
office365.runtime.client_request_exception.ClientRequestException: ('-1, Microsoft.SharePoint.Client.InvalidClientQueryException', 'The expression "Lists/GetById(53bef8eb-4048-4303-b939-0e582adc49e2)" is not valid.', '400 Client Error: Bad Request for url: https://<tenand-id>.sharepoint.com/teams/<team_name>/_api/Lists/GetById(53bef8eb-4048-4303-b939-0e582adc49e2)?$select=*')
Here's the callstack at the location where the problem occurs (on v.2.6.2):
is_string_type (office365\runtime\compat.py:41)
_encode_method_value (office365\runtime\paths\builder.py:56)
build_segment (office365\runtime\paths\builder.py:46)
segment (office365\runtime\paths\service_operation.py:16)
to_url (office365\runtime\paths\resource_path.py:38)
__str__ (office365\runtime\paths\resource_path.py:28)
resource_url (office365\runtime\client_object.py:227)
url (office365\runtime\queries\read_entity.py:31)
build_request (office365\runtime\odata\request.py:37)
execute_query (office365\runtime\client_request.py:36)
execute_query (office365\runtime\client_runtime_context.py:173)
execute_query (office365\runtime\client_object.py:55)
The culprit is in line 41 here:
|
def is_string_type(value): |
|
if is_py2: |
|
return isinstance(value, basestring) |
|
else: |
|
return type(value) is str |
Why not replace this with isinstance(value, str) which would cover subclasses of str such as StrEnum?
In certain situations, when passing subsclasses of
stras parameters, there are not recognized as strings and incorrectly encoded in a query.Specifically, I stumbled over this problem when passing a
enum.StrEnumto theoffice365.sharepoint.lists.collections.ListCollection.get_by_id()method. The resulting error resembles this (note the missing single quotes around the GUID):Here's the callstack at the location where the problem occurs (on v.2.6.2):
The culprit is in line 41 here:
office365-rest-python-client/office365/runtime/compat.py
Lines 37 to 41 in 8f6ce06
Why not replace this with
isinstance(value, str)which would cover subclasses ofstrsuch as StrEnum?