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

Added generic class based search views #1130

Merged
merged 10 commits into from Jan 14, 2015

Conversation

troygrosfield
Copy link
Contributor

This addresses the need for django-haystack's django style class based views. This is based on the discussion from the following PR:

This work was originally done by @bennylope with only minor changes from his original file:

This PR addresses the following issues:

@troygrosfield
Copy link
Contributor Author

The only test that's failing looks to be from a configuration change from elasticsearch which is causing all test runs to fail:

======================================================================
ERROR: test_kwargs_are_passed_on (test_haystack.elasticsearch_tests.test_elasticsearch_backend.TestSettings)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/toastdriven/django-haystack/test_haystack/elasticsearch_tests/test_elasticsearch_backend.py", line 204, in test_kwargs_are_passed_on
    backend = ElasticsearchSearchBackend('alias', **{'URL': {}, 'INDEX_NAME': 'testing', 'KWARGS': {'max_retries': 42}})
  File "/home/travis/build/toastdriven/django-haystack/haystack/backends/elasticsearch_backend.py", line 104, in __init__
    self.conn = elasticsearch.Elasticsearch(connection_options['URL'], timeout=self.timeout, **connection_options.get('KWARGS', {}))
  File "/home/travis/build/toastdriven/django-haystack/.eggs/elasticsearch-1.3.0-py2.6.egg/elasticsearch/client/__init__.py", line 150, in __init__
    self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
  File "/home/travis/build/toastdriven/django-haystack/.eggs/elasticsearch-1.3.0-py2.6.egg/elasticsearch/transport.py", line 113, in __init__
    self.set_connections(hosts)
  File "/home/travis/build/toastdriven/django-haystack/.eggs/elasticsearch-1.3.0-py2.6.egg/elasticsearch/transport.py", line 173, in set_connections
    self.connection_pool = self.connection_pool_class(connections, **self.kwargs)
  File "/home/travis/build/toastdriven/django-haystack/.eggs/elasticsearch-1.3.0-py2.6.egg/elasticsearch/connection_pool.py", line 106, in __init__
    specify at least one host.")
ImproperlyConfigured: No defined connections, you need to specify at least one host.

The failure doesn't have anything to do with this PR change.

I'm assuming the elasticsearch change is referring to:

ConnectionPool now checks if any connections were defined

@troygrosfield troygrosfield mentioned this pull request Jan 7, 2015
@troygrosfield
Copy link
Contributor Author

Added a fix for the elasticsearch tests which got some of the previously broken tests to successfully run again.

# this changed in change 1.7 to throw an error instead of
# returning None when the model isn't found. So catch the
# lookup error and keep self._model == None.
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_model raises LookupError instead of returning None when no model is found.

https://docs.djangoproject.com/en/1.7/releases/1.7/#introspecting-applications

This is also the first part of the fix to #1069.

@troygrosfield
Copy link
Contributor Author

The only tests now failing I would question if they should be failing. It has to do with django 1.7 and finding models. The remaining django 1.7 errors are as follows:

======================================================================
FAIL: test_missing_object (test_haystack.test_models.SearchResultTestCase)
----------------------------------------------------------------------
_UnexpectedSuccess: 
-------------------- >> begin captured logging << --------------------
haystack: ERROR: Object could not be found in database for SearchResult '<SearchResult: core.mockmodel (pk='1000000')>'.
haystack: ERROR: Model could not be found for SearchResult '<SearchResult: core.yetanothermockmodel (pk='1000000')>'.
haystack: ERROR: Model could not be found for SearchResult '<SearchResult: core.yetanothermockmodel (pk='1000000')>'.
haystack: ERROR: Model could not be found for SearchResult '<SearchResult: core.yetanothermockmodel (pk='1000000')>'.
--------------------- >> end captured logging << ---------------------

The tests are all passing, but since there are items added to the error log, the tests fail. The first one:

haystack: ERROR: Object could not be found in database for SearchResult '<SearchResult: core.mockmodel (pk='1000000')>'.

Is simply because the item was never saved to the database. It makes sense that this would show up in the logs so it could be cleaned up.

The 2nd, 3rd and 4th errors are:

haystack: ERROR: Model could not be found for SearchResult '<SearchResult: core.yetanothermockmodel (pk='1000000')>'.

which also make sense to see in the logs since yetanothermockmodel doesn't actually exist and the only way this case would happen in real life is if you:

  • had a model
  • indexed search results, then
  • removed the model

In that case, I would expect to see an error in the error log as well. So all these errors seem legit so why do we want this test to fail in these cases?

@troygrosfield
Copy link
Contributor Author

@acdha, @lehins, @bennylope any feedback?

@acdha
Copy link
Contributor

acdha commented Jan 8, 2015

I think the Django 1.7 errors should be deferred to another ticket - we already have one related to the various failures which are caused by the mock models. The last time @bigjust and I were talking about that, I was strongly in favor of discarding our legacy mock models entirely in favor normal models on the test app since the performance wins aren't worth the maintenance costs.

@troygrosfield
Copy link
Contributor Author

I would think these Django 1.7 changes would be welcome additions seeing how that part of the code was never updated in the first place to correctly reflect expected behavior in Django 1.7.

These fixes get the test suite closer to all passing which is a win all the way around if you ask me. I don't see the issue with those changes in this pr.

@troygrosfield
Copy link
Contributor Author

however, I would be happy to open up a new ticket after this pr is merged based on the comment I made about the remaining portion of the Django 1.7 tests not passing at:

Thoughts?

@acdha
Copy link
Contributor

acdha commented Jan 9, 2015

@troygrosfield Sorry, that wasn't clearly phrased: I have no objection to including those fixes in this ticket – I just figured it'd be good to defer anything which isn't necessary to making the new CBVs work so you don't feel like you have to fix unrelated test failures to get this merged.

@troygrosfield
Copy link
Contributor Author

Happy to help the open source community! This is a good project and I want to see it succeed.

With that said, are there any objections to getting this merged?

@acdha acdha self-assigned this Jan 12, 2015
@troygrosfield
Copy link
Contributor Author

@acdha, do you have privs to merge? Are we waiting on anything here?

@acdha
Copy link
Contributor

acdha commented Jan 13, 2015

The biggest thing I'd like to see would be some tests for the new views to avoid any future regressions.

@troygrosfield
Copy link
Contributor Author

Tests have been added.

@acdha
Copy link
Contributor

acdha commented Jan 13, 2015

This is looking good – also like we can remove this expected failure?

https://travis-ci.org/toastdriven/django-haystack/jobs/46879996#L1367

@troygrosfield
Copy link
Contributor Author

Are you referring to the following lines in test_haystack.test_models.SearchResultTestCase:

if django.VERSION >= (1, 7, 0):
        # FIXME: https://github.com/toastdriven/django-haystack/issues/1069
        test_missing_object = unittest.expectedFailure(test_missing_object)

?

@acdha
Copy link
Contributor

acdha commented Jan 13, 2015

Yes - the Travis logs made it look like that passed:

======================================================================

FAIL: test_missing_object (test_haystack.test_models.SearchResultTestCase)

----------------------------------------------------------------------

nose.proxy._UnexpectedSuccess: 

@troygrosfield
Copy link
Contributor Author

That was already there. This PR didn't change that behavior. However, I'll go ahead and remove it because I don't think it should be there either.

@troygrosfield
Copy link
Contributor Author

Done. The following job needs to be rerun in travis:

After that, all tests should be successfully passing now.

acdha added a commit that referenced this pull request Jan 14, 2015
Added generic class based search views 

(thanks @troygrosfield)
@acdha acdha merged commit 74b9eba into django-haystack:master Jan 14, 2015
@acdha
Copy link
Contributor

acdha commented Jan 14, 2015

Next we need to mark the legacy view documentation as deprecated and update it for the new CBVs.

@troygrosfield
Copy link
Contributor Author

👍

@troygrosfield
Copy link
Contributor Author

@acdha, is there a new release planned to push out the new changes anytime soon?

@acdha acdha added this to the v2.4.0 milestone Jan 14, 2015
@acdha
Copy link
Contributor

acdha commented Jan 14, 2015

There's a fair amount of stuff stacked up for 2.4 which is probably due for another triage round:

https://github.com/toastdriven/django-haystack/milestones/v2.4.0

@SalahAdDin
Copy link

You guys are working very hard for update haystack, thank you very much :D

@dekoza
Copy link

dekoza commented Jan 27, 2015

@troygrosfield THANK YOU for this! These are the changes I was looking forward to for quite some time.

@troygrosfield
Copy link
Contributor Author

No problem. Happy to help!

@acdha
Copy link
Contributor

acdha commented Jan 27, 2015

@dekoza We still have an open ticket to update the documentation – #1133. Feel free to comment there if you have any advice for other users

@troygrosfield
Copy link
Contributor Author

PR is out for the doc to resolve #1133:

@acdha acdha mentioned this pull request Feb 3, 2015
acdha added a commit to acdha/django-haystack that referenced this pull request Feb 3, 2015
@SalahAdDin
Copy link

Whats about FacetedSearch Views and Forms in 2.4?

@troygrosfield
Copy link
Contributor Author

@acdha, any word on when this (2.4) will be released?

@SalahAdDin
Copy link

No idea 👍

@acdha
Copy link
Contributor

acdha commented Jun 5, 2015

There's a release candidate on PyPI now:

pip install django-haystack==2.4.0rc1

@SalahAdDin
Copy link

Wow, but, i prefers wait for the oficial release :D.
Thank you. 👍

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