etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.2k stars 130 forks source link

buildwatson command error with Django 1.7 #217

Closed Sovetnikov closed 6 years ago

Sovetnikov commented 6 years ago

I'm writing this just in case someone with Django 1.7 have troubles using django-watson.

With django-watson version 1.4.0 "manage.py buildwatson" command gives error on Django 1.7:

File "C:\Python34\lib\site-packages\django\core\management__init.py", line 385, in execute_from_command_line utility.execute() File "C:\Python34\lib\site-packages\django\core\management__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.dict__) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 338, in execute output = self.handle(*args, *options) File "C:\Python34\lib\site-packages\django\db\transaction.py", line 394, in inner return func(args, **kwargs) File "C:\Python34\lib\site-packages\watson\management\commands\buildwatson.py", line 95, in handle if len(options['apps']): KeyError: 'apps'

Solution is very simple - just add check if 'apps' key in options, but i think there is no reason to make this fix in latest version because it is not compatible with Django 1.7 and error is only for 1.7.

Just in case anyone is still with Django 1.7 - one solution is to monkeypatch django-watson 1.4.0:

class CustomConfig(AppConfig):
    name = "web"

    def ready(self):
        from watson.management.commands.buildwatson import Command as BuildWatsonCommand
        _bwc_handle_original = BuildWatsonCommand.handle
        def _bwc_handle(self, *args, **options):
            if not 'apps' in options:
                options['apps'] = []
            _bwc_handle_original(self, *args, **options)
        BuildWatsonCommand.handle = _bwc_handle

        watson.register(self.get_model("Product"))
etianen commented 6 years ago

I'm afraid there are a couple of things breaking backwards compatibility with Django 1.7 in the main release line now. Given Django 1.7 is no longer supported by the core team, it's definitely time for people to upgrade.