Skip to content

Commit

Permalink
Encode schedule filename with filesystem encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfriend committed May 6, 2020
1 parent 411413f commit e8ed3f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions celery/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,20 @@ def __init__(self, *args, **kwargs):
Scheduler.__init__(self, *args, **kwargs)

def _remove_db(self):
if not self.schedule_filename:
return
for suffix in self.known_suffixes:
with platforms.ignore_errno(errno.ENOENT):
os.remove(self.schedule_filename + suffix)
schedule = self.schedule_filename + suffix
os.remove(schedule.encode(sys.getfilesystemencoding()))

def _open_schedule(self):
return self.persistence.open(self.schedule_filename, writeback=True)
schedule = None
if self.schedule_filename:
schedule = self.schedule_filename.encode(
sys.getfilesystemencoding()
)
return self.persistence.open(schedule, writeback=True)

def _destroy_open_corrupted_schedule(self, exc):
error('Removing corrupted schedule file %r: %r',
Expand Down
7 changes: 7 additions & 0 deletions t/unit/app/test_beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ def effect(*args, **kwargs):
s.setup_schedule()
s._store.clear.assert_called_with()

def test_setup_schedule_real_shelve_unicode_filename(self, tmpdir):
s = beat.PersistentScheduler(
app=self.app,
schedule_filename=unicode(tmpdir.join('schedule'))
)
s.setup_schedule()

def test_get_schedule(self):
s = create_persistent_scheduler()[0](
schedule_filename='schedule', app=self.app,
Expand Down

0 comments on commit e8ed3f6

Please sign in to comment.