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

Experimental query builder

Open RogerSelwyn opened this issue 7 months ago • 14 comments

Opening this thread to separate from other items.

Running this code results in the error shown below:

builder = ExperimentalQuery(protocol=account.protocol)
schedule = account.schedule()
calendars = schedule.list_calendars()
calendar = calendars[1]
query = builder.select(
    "subject",
    "body",
)
start = datetime.now()
end = datetime.now() + timedelta(weeks=1)

query = query & (builder.greater_equal("start", start) & builder.less_equal("ent", end))

events = calendar.get_events(query=query)
Exception has occurred: AttributeError
'CompositeFilter' object has no attribute '_filters'
  File "/HADev/Hassio/dev-config/O365/calendar.py", line 1799, in get_events
    for query_data in query._filters:
                      ^^^^^^^^^^^^^^
  File "/HADev/Hassio/dev-config/bash_o365_query.py", line 57, in <module>
    events = calendar.get_events(query=query)
AttributeError: 'CompositeFilter' object has no attribute '_filters'

Calendar shouldn't really be accessing _filters, but it is using it to extract start and end date. Can't easily see the resolution.

RogerSelwyn avatar Apr 22 '25 12:04 RogerSelwyn

I've used a number of other methods in the query builder, which have all worked. Not tried everything though.

RogerSelwyn avatar Apr 22 '25 13:04 RogerSelwyn

Wow! didn't remember that... Thanks for the finding! I'll look into this and try to solve it

alejcas avatar Apr 22 '25 16:04 alejcas

Wow! didn't remember that... Thanks for the finding! I'll look into this and try to solve it

Probably ought to be extracting them from the query more directly in get_events, or provide a method on query to pop them. But it needs to be backward compatible to allow a migration.

RogerSelwyn avatar Apr 22 '25 16:04 RogerSelwyn

Wow! didn't remember that... Thanks for the finding! I'll look into this and try to solve it

Probably ought to be extracting them from the query more directly in get_events, or provide a method on query to pop them. But it needs to be backward compatible to allow a migration.

I know to fix it. But I will have to change Calendar.get_events and both ExperimentalQuery and the old query for users to be able to work with both. So users will be able to use one or another on the next version.

alejcas avatar Apr 22 '25 16:04 alejcas

As it stands, the code posted above still errors as below:

Traceback (most recent call last):
  File "/HADev/Hassio/dev-config/bash_o365_query.py", line 69, in <module>
    events = calendar.get_events(query=query)
  File "/HADev/Hassio/dev-config/O365/calendar.py", line 1828, in get_events
    start = query.get_filter_by_attribute('start/')
  File "/HADev/Hassio/dev-config/O365/utils/query.py", line 45, in get_filter_by_attribute
    search_object: Optional[QueryFilter] = getattr(self, "_filter_instance") or getattr(self, "filters")
                                           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CompositeFilter' object has no attribute '_filter_instance'

EDIT: Not sure if you have finished your changes yet...

RogerSelwyn avatar Apr 27 '25 16:04 RogerSelwyn

I’ve not finished all the changes! I’ll report back next week

alejcas avatar Apr 27 '25 16:04 alejcas

With the PR I submitted on schedule.get_events as far as I can see it all works for me.

RogerSelwyn avatar May 08 '25 08:05 RogerSelwyn

Do you know when you will release? I just need to manage changes at my end, because I have the dependency to o365 unpinned, and it will break my calendar integration. Not a problem, just so I can do updates at the right time.

RogerSelwyn avatar May 18 '25 10:05 RogerSelwyn

Do you know when you will release? I just need to managed changes at my end, because I have the dependency to o365 unpinned, and it will break my calendar integration. Not a problem, just so I can do updates at the right time.

Next week!

alejcas avatar May 22 '25 12:05 alejcas

Next week!

This week? I go on holiday and the end of next week for a bit under 3 weeks.

RogerSelwyn avatar Jun 02 '25 11:06 RogerSelwyn

Sorry @RogerSelwyn. I have had quite some nightmares at work. I'll try to do it asap this week

alejcas avatar Jun 02 '25 15:06 alejcas

No problem. Work always gets in the way.

RogerSelwyn avatar Jun 02 '25 15:06 RogerSelwyn

@alejcas don’t rush this weekend. To be honest it won’t leave enough time between me being able to release and me going away to deal with any issues. I’ll wait to release until after I get back in very early July.

RogerSelwyn avatar Jun 02 '25 17:06 RogerSelwyn

@RogerSelwyn 2.1.3 released

I had to add a deprecation warning when using old query objects.

alejcas avatar Jun 03 '25 08:06 alejcas