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

ruleset.count() not changing after applying ruleset.exrule() #104

Closed
anandkr07 opened this issue Aug 12, 2015 · 2 comments
Closed

ruleset.count() not changing after applying ruleset.exrule() #104

anandkr07 opened this issue Aug 12, 2015 · 2 comments
Assignees
Milestone

Comments

@anandkr07
Copy link

Seems like the ruleset.count() is getting cached after first call to it. An Example of this behavior -

>>> rules = rrule.rruleset()
>>> rules.rrule(rrule.rrule(rrule.DAILY, until=datetime.datetime(2038,1,1,0,0,0), dtstart=datetime.datetime(now.year,now.month,now.day,0,0,0)))
>>> rules.count()
8179
>>> rules.exrule(rrule.rrule(rrule.DAILY, until=datetime.datetime(2038,1,1,0,0,0), dtstart=datetime.datetime(now.year,now.month,now.day,0,0,0)))
>>> rules.count()
8179

Only after iterating over the ruleset , do we get the correct value , Example -

>>> list(rules)
[]
rules.count()
0
@pganssle pganssle added this to the 2.5.0 milestone Aug 12, 2015
@pganssle pganssle self-assigned this Aug 12, 2015
@pganssle
Copy link
Member

The issue here is that rrulebase caches the length after the first call to count(), and this cache is not invalidated when changes are made to the rruleset:

from datetime import datetime as dt
from dateutil import rrule as rr

dts = dt(2015, 8, 11)
dte = dt(2016, 8, 11)

crr = rr.rrule(rr.DAILY, dtstart=dts, until=dte)

rules = rr.rruleset()
print(rules.count())
>>> 0

rules.rrule(crr)
print(rules.count())
>>> 0

rules._len = None
print(rules.count())
>>> 367

This should be easy enough to fix, I can make sure it's fixed in 2.5.0. I am in general loathe to recommend building anything upon private methods or attributes, but in the meantime, anything that iterates over the rruleset should update the count, so list(rules) or something like: for _ in rules: pass (this is what rruleset.count() would be doing anyway if the cache were properly invalidated anyway, so it shouldn't degrade performance).

Thanks for the bug report!

@pganssle pganssle modified the milestones: 2.5.1, 2.5.0 Nov 2, 2015
@pganssle
Copy link
Member

pganssle commented Nov 2, 2015

Pushing fix to 2.5.1 to speed release of 2.5.0.

@pganssle pganssle modified the milestones: 2.5.1, Next bugfix release Mar 3, 2016
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

2 participants