Skip to content
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

O365.utils.utils.Query.any does not support negate() and does not follow the group? #1058

Open
execcr opened this issue Mar 6, 2024 · 4 comments

Comments

@execcr
Copy link

execcr commented Mar 6, 2024

Hi, i was trying to rewrite this query that is working with Psotman and the O365 messages endpoint:
NOT(categories/any(a:a eq 'Category1') or categories/any(a:a eq 'Category2'))

I had thought that this could have been the equivalent code (Note: the operation=ne is not supported with categories):

query = mailbox.new_query()
query.open_group().negate()
query.all(collection='categories', word="Category1", operation='eq')
query.chain('or')
query.any(collection='categories', word=''Category2', operation='eq')
query.close_group()

but the output had the "not" missing:
Filter is: {'$filter': "(categories/any(a:a eq 'Category1') or categories/any(a:a eq 'Category2'))"}
With the on_Attribute method the filter is producing this output:
Query:

query = mailbox.new_query()
query.negate()
query.open_group()
query = query.on_attribute('subject').contains('value1')
query = query.chain('or')
query = query.on_attribute('subject').contains('value2')
query.close_group()

Output:
Filter is {'$filter': "(not contains(subject, 'value1') or not contains(subject, 'value2'))"}
I would expect this output:

{'$filter': "not(contains(subject, 'value1') or contains(subject, 'value2'))"}any hint?

@alejcas
Copy link
Member

alejcas commented Mar 6, 2024

query.open_group().negate()

Does nothing.

assign to query again:

query = query.open_group().negate()

and do the same for the following

@execcr
Copy link
Author

execcr commented Mar 7, 2024

Thanks, i've tried as you says. The result is the same. The not negation is not added to the filter.

This is the code:

query = mailbox.new_query()
query = query.open_group().negate()
query = query.any(collection='categories', word="Category1", operation='eq')
query = query.chain('or')
query = query.any(collection='categories', word='Category2', operation='eq')
query = query.close_group()

this is the filter created:
Filtro creato: {'$filter': "(categories/any(a:a eq 'Category1') or categories/any(a:a eq 'Category2'))"}

@alejcas
Copy link
Member

alejcas commented Apr 12, 2024

I see! I'll try to fix it

Query can either be a Query object or a string, so pass the string filter you want for now

alejcas pushed a commit that referenced this issue Apr 12, 2024
Fixed: Negations are now correctly consumed when used in: open groups, logical operators, functions and iterables.
@alejcas
Copy link
Member

alejcas commented Apr 12, 2024

Fixed in 094399b

To negate groups (or anything) the negate should go BEFORE the action, so:

query = mailbox.new_query()
query = query.negate().open_group()  # negate goes first! or otherwise will negate the first any on the group
query = query.any(collection='categories', word="Category1", operation='eq')
query = query.chain('or')
query = query.any(collection='categories', word='Category2', operation='eq')
query = query.close_group()

You can also negate the condition inside the 'any' or 'all' iterables using the negation argument:

query = mailbox.new_query()
query = query.negate().any(collection='categories', word="Category1", operation='eq', negation=True)
print(query)

This outputs:

Filter: not categories/any(a:not a eq 'Category1')
Order: None
Select: None
Expand: None
Search: None

Please report back if this now works as expected

Thanks

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

No branches or pull requests

2 participants