Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

optparse.make_option method is deprecated in Django 1.10 #75

Closed bctiemann closed 8 years ago

bctiemann commented 8 years ago

Running runcrons:

.../venv/lib/python2.7/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead RemovedInDjango110Warning)

Looks like all you need to do is replace the "option_list" block at the top of the Command class with:

def add_arguments(self, parser):
    parser.add_argument('--force', action='store_true', help='Force cron runs')
    parser.add_argument('--silent', action='store_true', help='Do not push any message on console')
prokaktus commented 8 years ago

Doesn't it break backward-compatibility? Looks like it did. Because add_arguments was added in Django 1.8.

@bctiemann do you know recommended way to check Django version and depending on it define or not define attributes and functions?

bctiemann commented 8 years ago

I'm not sure if there's a canonical way, but what if you check whether the add_arguments method is defined in the BaseCommand superclass?

prokaktus commented 8 years ago

@bctiemann thanks for your suggestion!

akhayyat commented 8 years ago

Django 1.10 has now been released, and this issue no longer is a deprecation warning; it breaks django-cron on Django 1.10. Upon running the manage.py runcrons, I get:

AttributeError: type object 'BaseCommand' has no attribute 'option_list'

Could a fixed release be made available? That would be greatly appreciated!

BTW, it seems to be common to check Django's version using django.get_version() (string) or django.VERSION (tuple) to support multiple versions and avoid breaking backward compatibility, e.g.:

if django.get_version().split('.') < ['1', '10']:
    # old version friendly code
else:
    # new version friendly code
chachra commented 8 years ago

@akhayyat - acknowledged and we'll work on a fix asap.

maxim-kht commented 8 years ago

The fix is deployed https://pypi.python.org/pypi/django-cron/

akhayyat commented 8 years ago

Works perfectly! Thank you very much for the prompt resolution.