Skip to content

Error Filtering Non-Indexed Field in SharePoint List #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jsormaz opened this issue Mar 10, 2021 · 3 comments
Open

Error Filtering Non-Indexed Field in SharePoint List #593

jsormaz opened this issue Mar 10, 2021 · 3 comments

Comments

@jsormaz
Copy link

jsormaz commented Mar 10, 2021

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
Copy link
Author

jsormaz commented Mar 10, 2021

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

@Slothfulwave612
Copy link

@alejcas Hi, hope you are in good health. I encountered a similar issue in one of my projects and had to download the repository to make the change manually. I noticed this hasn’t been updated in the O365 script. If it’s okay with you, I would like to make this change in the script and submit a pull request. Please let me know if that works for you—I’d be happy to help!

@alejcas
Copy link
Member

alejcas commented Apr 1, 2025

@alejcas Hi, hope you are in good health. I encountered a similar issue in one of my projects and had to download the repository to make the change manually. I noticed this hasn’t been updated in the O365 script. If it’s okay with you, I would like to make this change in the script and submit a pull request. Please let me know if that works for you—I’d be happy to help!

It's perfectly fine. Just submit a PR.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants