python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Error Filtering Non-Indexed Field in SharePoint List

Open jsormaz opened this issue 3 years ago • 1 comments

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)

jsormaz avatar Mar 10 '21 20:03 jsormaz

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

jsormaz avatar Mar 10 '21 21:03 jsormaz