python-o365
python-o365 copied to clipboard
Experimental query builder
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.
I've used a number of other methods in the query builder, which have all worked. Not tried everything though.
Wow! didn't remember that... Thanks for the finding! I'll look into this and try to solve it
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.
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.
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...
I’ve not finished all the changes! I’ll report back next week
With the PR I submitted on schedule.get_events as far as I can see it all works for me.
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.
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!
Next week!
This week? I go on holiday and the end of next week for a bit under 3 weeks.
Sorry @RogerSelwyn. I have had quite some nightmares at work. I'll try to do it asap this week
No problem. Work always gets in the way.
@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 2.1.3 released
I had to add a deprecation warning when using old query objects.