python-o365
python-o365 copied to clipboard
Error Filtering Non-Indexed Field in SharePoint List
When I try to filter on a non-indexed field, I get the following error:
Error Message: Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.
How can I provide the header as described? It is not feasible for me to index every field that I need to filter by. I do not have an issue of large lists.
I am filtering using the following method:
query = sharepoint_list.q().expand('fields').select('Title','id')
query.chain().on_list_field('Title').equals('filter value')
matching_items = sharepoint_list.get_items(query = query)
I was able to hack this together by replacing line:
response = self.con.get(url, params=params)
in sharepoint.py get_items()
with:
headers = {}
headers['Prefer'] = 'HonorNonIndexedQueriesWarningMayFailRandomly'
response = self.con.get(url, params=params, headers=headers)
however I would prefer a built in solution