summaryrefslogtreecommitdiff
path: root/apscheduler
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2016-11-06 10:40:50 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2016-11-06 10:40:50 +0200
commitf075d15c141ad9ae6ea7b4873db3e8acbc18627d (patch)
tree6b2a21bd73a933fee710f4d5eaeaa8dcde33e875 /apscheduler
parent0802351ef10e37fa82ed2da76fa25779c5f87ee3 (diff)
downloadapscheduler-f075d15c141ad9ae6ea7b4873db3e8acbc18627d.tar.gz
Fixed @scheduled_job not playing nice with persistent job stores (fixes #150)
Diffstat (limited to 'apscheduler')
-rw-r--r--apscheduler/util.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/apscheduler/util.py b/apscheduler/util.py
index d6d5c47..9139789 100644
--- a/apscheduler/util.py
+++ b/apscheduler/util.py
@@ -4,6 +4,7 @@ from __future__ import division
from datetime import date, datetime, time, timedelta, tzinfo
from calendar import timegm
import re
+from functools import partial
from pytz import timezone, utc
import six
@@ -229,20 +230,24 @@ def get_callable_name(func):
def obj_to_ref(obj):
"""
- Returns the path to the given object.
+ Returns the path to the given callable.
:rtype: str
+ :raises TypeError: if the given object is not callable
+ :raises ValueError: if the given object is a :class:`~functools.partial`, lambda or a nested
+ function
"""
- try:
- ref = '%s:%s' % (obj.__module__, get_callable_name(obj))
- obj2 = ref_to_obj(ref)
- if obj != obj2:
- raise ValueError
- except Exception:
- raise ValueError('Cannot determine the reference to %r' % obj)
+ if isinstance(obj, partial):
+ raise ValueError('Cannot create a reference to a partial()')
+
+ name = get_callable_name(obj)
+ if '<lambda>' in name:
+ raise ValueError('Cannot create a reference to a lambda')
+ if '<locals>' in name:
+ raise ValueError('Cannot create a reference to a nested function')
- return ref
+ return '%s:%s' % (obj.__module__, name)
def ref_to_obj(ref):