find_comment(comment) with multiple same comment does not return whole job list

Bug #1628844 reported by Marcq Nicolas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-crontab
Fix Committed
High
Martin Owens

Bug Description

Hi, the method find_comment() seems to not return all lines if we have a mutliple time the same comment name in the crontab.

Step to reproduce:

command = "/path/to/my/command"
comment = "SAMECOMMENT"
period_string = "* * 5 5 *"

my_user_cron = CronTab(user=True)

for x in range(0, 5, 1):
    job = my_user_cron.new(command=command, comment=comment)
    if CronSlices.is_valid(period_string):
        job.setall(period_string)
        job.enable()
    my_user_cron.write()

# here we have:
# * * 5 5 * /path/to/my/command # SAMECOMMENT
# * * 5 5 * /path/to/my/command # SAMECOMMENT
# * * 5 5 * /path/to/my/command # SAMECOMMENT

# remove all SAMECOMMENT job
iter = my_user_cron.find_comment(comment)
for job in iter:
    print "remove job %s" % job
    my_user_cron.remove(job)
my_user_cron.write()

# now we check the content
new_iter = my_user_cron.find_comment(comment)
for job in iter:
    print "Still a job: %s" % job

# output
# remove job * * 5 5 * /path/to/my/command # SAMECOMMENT
# remove job * * 5 5 * /path/to/my/command # SAMECOMMENT
# Still a job: * * 5 5 * /path/to/my/command # SAMECOMMENT

Revision history for this message
Martin Owens (doctormo) wrote :

I've committed a fix. This was an iterator issue, where removal of the items would shorten the list and cause the next iteration to skip one.

Test is now in place to catch this error.

Changed in python-crontab:
assignee: nobody → Martin Owens (doctormo)
importance: Undecided → High
milestone: none → 2.2
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.