using for with remove skips a job

Bug #1539178 reported by Adam Rothschild
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-crontab
Fix Released
Medium
Martin Owens

Bug Description

for job in cron:
    print (job)
    cron.remove(job)
cron.write()

This method removes every other job.
Starting crontab

1 1 * * * /usr/bin/echo # comment1
1 2 * * * /usr/bin/echo # comment2
1 3 * * * /usr/bin/echo # comment3
1 4 * * * /usr/bin/echo # comment4
1 5 * * * /usr/bin/echo # comment5
1 6 * * * /usr/bin/echo # comment6
1 7 * * * /usr/bin/echo # comment7
1 8 * * * /usr/bin/echo # comment8
1 9 * * * /usr/bin/echo # comment9
1 10 * * * /usr/bin/echo # comment10

output
1 1 * * * /usr/bin/echo # comment1
1 3 * * * /usr/bin/echo # comment3
1 5 * * * /usr/bin/echo # comment5
1 7 * * * /usr/bin/echo # comment7
1 9 * * * /usr/bin/echo # comment9

crontab after
1 2 * * * /usr/bin/echo # comment2
1 4 * * * /usr/bin/echo # comment4
1 6 * * * /usr/bin/echo # comment6
1 8 * * * /usr/bin/echo # comment8
1 10 * * * /usr/bin/echo # comment10

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

I've committed a fix for the issue as well as a test that failed before and doesn't now.

Changed in python-crontab:
assignee: nobody → Martin Owens (doctormo)
importance: Undecided → Medium
milestone: none → 2.1
status: New → Fix Committed
Martin Owens (doctormo)
Changed in python-crontab:
status: Fix Committed → Fix Released
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.