Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.0 compatibility #1582

Merged
merged 31 commits into from Mar 9, 2018
Merged

Django 2.0 compatibility #1582

merged 31 commits into from Mar 9, 2018

Conversation

mpauly
Copy link

@mpauly mpauly commented Jan 2, 2018

Hi,
this PR adds Django 2.0 compatibility.
As the PR #1557 did not see any progress recently I implemented everything needed for Django 2.0 compatibility here.

In particular I rewrote the rebuild_index command to strip certain arguments that are not used in the clear_index and update_index commands respectively. This is implemented in a relatively adhoc way, however looking at the amount of changes made to rebuild_index in the past I figured this might be the easiest way to implement this change.

Additionally I added Django 2.0 to the tests and excluded the combination Django2.0 + Python2.7 from the test suite so that the tests still pass. Maybe one should also consider adding python 3.6 to the test suite, however I did not do that yet.

Also note the change I made to test_haystack/solr_tests/test_solr_backend.py. This was necessary due to the recent update in pysolr. That update broke the django-haystack tests, as pysolr.__version__ is now a string instead of a tuple. The fix I implemented should be backwards compatible.

Please let me know if there is anything this MR needs to get merged, cheers,
Martin

@@ -1458,7 +1458,7 @@ def test_boost(self):
])


@unittest.skipIf(pysolr.__version__ < (3, 1, 1), 'content extraction requires pysolr > 3.1.0')
@unittest.skipIf(tuple(pysolr.__version__.split('.')) < (3, 1, 1), 'content extraction requires pysolr > 3.1.0')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also use pysolr.version_info but that will trigger a deprecation warning on setuptools >= 8.0 since that's no longer a simple tuple.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually seems to have an additional problem as the parsed version still contains strings instead of integers.
Either we could do a pysolr.version_info < parse_version('3.1.1') with the corresponding import or we just drop that annotation? Seems relatively unlikely that anyone is running the test suite with a version of pysolr from 2013, no?
What do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping it does make sense - if anyone is running tests on an install that old it seems unlikely that they'd have upgraded haystack but frozen pysolr

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I dropped the annotation.

@mpauly
Copy link
Author

mpauly commented Jan 3, 2018

By the way, thank you @acdha for replying so fast and maintaining django-haystack!

Anything else that needs updating in this MR?

@acdha
Copy link
Contributor

acdha commented Jan 3, 2018

I wanted to review it in more detail first but at first glance it looked good

@mpauly
Copy link
Author

mpauly commented Jan 19, 2018

@acdha did you already have time to take a look at this MR? any way I can support you in getting this merged?

@dani0805
Copy link

I can vouch for this, we have been using @mpauly fork for 2 days in our dev branch and it works like a charm.

@acdha
Copy link
Contributor

acdha commented Jan 21, 2018

@mpauly the main thing is testing – since I’m not using that combination at the moment I haven’t done more than look at the code. I’d like to e.g. confirm test coverage isn’t omitting anything important.

@mpauly
Copy link
Author

mpauly commented Jan 21, 2018

@acdha I just added a test to see if ModelSearchIndex properly excludes related fields by default - seems this was not tested before. I also updated the corresponding line in haystack/indexes.py as my changes were not working as they should on Django 2.0. Now everything should be working fine and the tests pass on my travis, somehow on yours they don't - see https://travis-ci.org/mpauly/django-haystack.

Is there any reason why field.is_relation was not used before? That seems to be the most generic way to check if a field is a related_field.

@mpauly
Copy link
Author

mpauly commented Jan 30, 2018

@acdha I just merged master into this branch (I probably should have rebased - sorry about that)
Additionally I can report that we are using this branch for a few days in our staging environment and at least in our setup it seems to work well.

@mpauly
Copy link
Author

mpauly commented Feb 12, 2018

It seems that before I was not running the solr tests correctly, so I had to do more updates to fix some failing tests. Over the weekend I did the following changes:

  1. I dropped support for Django < 1.11 - I also tried to cleanup the tox.ini, the travis file and setup.py
  2. I added Python 3.6 to the tests in travis
  3. I had to replace get_coords() by coords in multiple places to fix some tests
  4. I updated some of the test configuration to work properly with Django 2.0

There might potentially be bugs in some functionality related to the geo lookups, however tests are passing with Django 1.11 and 2.0. We are also running this fork in production with Django 2.0 and have not experienced any problems yet.

Copy link
Contributor

@timgraham timgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add:

'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',

to setup.py.

.travis.yml Outdated
- DJANGO_VERSION=">=1.8,<1.9" VERSION_ES=">=2.0.0,<3.0.0"
- DJANGO_VERSION=">=1.9,<1.10" VERSION_ES=">=2.0.0,<3.0.0"
- DJANGO_VERSION=">=1.10,<1.11" VERSION_ES=">=2.0.0,<3.0.0"
- DJANGO_VERSION=">=1.11,<1.12" VERSION_ES=">=1.0.0,<2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<1.12 -> <2.0

.travis.yml Outdated

matrix:
allow_failures:
- python: 'pypy'
- python: 2.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These builds should be excluded rather than "allowed_failures".

@@ -33,5 +34,11 @@ def add_arguments(self, parser):
)

def handle(self, **options):
call_command('clear_index', **options)
call_command('update_index', **options)
clear_options = copy.copy(options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.copy()?

@@ -2,11 +2,12 @@

from __future__ import absolute_import, division, print_function, unicode_literals

import django
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

setup.py Outdated
@@ -12,7 +12,7 @@
from setuptools import setup

install_requires = [
'Django>=1.8,<1.12',
'Django>=1.11,<2.1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't specify an upper bound -- it might be that this will work fine with Django 2.1 without any changes.

tox.ini Outdated
deps =
Django>=1.8,<1.9
Django>=1.11,<1.12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<2.0

"""
Confirm that command-line option parsing produces the same results as using call_command() directly,
mostly as a sanity check for the logic in rebuild_index which combines the option_lists for its
component commands.
"""
from haystack.management.commands.rebuild_index import Command

update_mock.return_value = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put return_value='' in the @patch calls.

@@ -623,6 +629,7 @@ def test_excludes(self):
self.assertTrue(isinstance(self.emsi.fields['pub_date'], indexes.DateTimeField))
self.assertTrue('text' in self.emsi.fields)
self.assertTrue(isinstance(self.emsi.fields['text'], indexes.CharField))
self.assertFalse('related_models' in self.m2mmsi.fields)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertNotIn

@@ -69,6 +69,9 @@ def test_rebuild_index_using(self, m1, m2):
@patch('haystack.management.commands.update_index.Command.handle')
@patch('haystack.management.commands.clear_index.Command.handle')
def test_rebuild_index(self, mock_handle_clear, mock_handle_update):
mock_handle_clear.return_value = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put return_value='' in the @patch calls.

args, kwargs = clear_mock.call_args

self.assertIn('interactive', kwargs)
self.assertEqual(False, kwargs['interactive'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for boolean comparisons: self.assertIs(kwargs['interactive'], False)

@mpauly
Copy link
Author

mpauly commented Feb 12, 2018

@timgraham Thanks for the comments, all of them should be implemented now.

@webtweakers
Copy link

I can confirm that @mpauly's fork works fine with Django 2.0. Tested rebuild_index command, searching, faceting and autocomplete in combination with ElasticSearch. No problems here.

@michaelmior
Copy link

In my case, django-haystack 2.7.0 works fine with Django 2 without any changes. Would be great to have this explucitly supported though.

@nadimtuhin
Copy link

waiting for d2 support :D

@JonLevischi
Copy link

Any idea when this branch will be officially committed to the master package?
Thanks

@acdha
Copy link
Contributor

acdha commented Mar 2, 2018 via email

@RabidCicada
Copy link
Contributor

@acdha WRT more people testing, what are we looking for? 5, 10? I don't have a production system. But I'm happy to test with my rinky dink setup, and vouch if it works for me. How many vouchsafes are we short? I don't think people, myself, included like fuzzy "more people" statements.

@acdha
Copy link
Contributor

acdha commented Mar 2, 2018 via email

@RabidCicada
Copy link
Contributor

Ahh...very good clarification. Thanks. I wont be able to help much on that front :)

@nadimtuhin
Copy link

tested with django 2 & elasticsearch on aws, everything worked fine

@JonLevischi
Copy link

Apparently it will work with Whoosh on AWS as well.

@mpauly
Copy link
Author

mpauly commented Mar 3, 2018

We are running Xapian-haystack, that works well with this branch

acdha added a commit to acdha/django-haystack that referenced this pull request Mar 9, 2018
Thanks to @mpauly and @timgraham for working on this and @dani0805,
@andrewbenedictwallace, @RabidCicada, @webtweakers, @nadimtuhin, and
@JonLevischi for testing.
@acdha acdha mentioned this pull request Mar 9, 2018
2 tasks
acdha added a commit to acdha/django-haystack that referenced this pull request Mar 9, 2018
Thanks to @mpauly and @timgraham for working on this and @dani0805,
@andrewbenedictwallace, @RabidCicada, @webtweakers, @nadimtuhin, and
@JonLevischi for testing.
@acdha acdha merged commit 40cbee5 into django-haystack:master Mar 9, 2018
@acdha
Copy link
Contributor

acdha commented Mar 9, 2018

This is now in https://pypi.python.org/pypi/django-haystack/2.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants