algolia / algoliasearch-django

Seamless integration of Algolia into your Django project.
https://www.algolia.com
MIT License
173 stars 65 forks source link

Algolia prevents running or testing django offline #237

Closed oliver-zhou closed 6 years ago

oliver-zhou commented 6 years ago

Running and testing locally is difficult when I have an unstable/no internet connection, yielding this exception:

algoliasearch.helpers.AlgoliaException: Unreachable hosts

There should be a mechanism to automatically swallow these errors. It seems these exceptions are run as warnings instead of exceptions in production, this behavior should be allowed to persist when DEBUG=True still if given a flag in settings or something.

I can make a pull request if that's something that makes sense

Line in question:

https://github.com/algolia/algoliasearch-django/blob/4987a5df2d7cdcb0e81563babcf0c7f5aeba6a05/algoliasearch_django/models.py#L297-L302

PLNech commented 6 years ago

Hi @oliver-zhou, thanks for your report! There is already such a mechanism, but the readme lacks its description.

See the ChangeLog of V1.3.0:

  * [ADD] Option to raise or not exceptions. By default, raise only when DEBUG=True

And the code of settings.py defining settings.DEBUG:

from django.conf import settings

SETTINGS = settings.ALGOLIA
DEBUG = SETTINGS.get('RAISE_EXCEPTIONS', settings.DEBUG)

If you want to disable the raising of exceptions, simply set RAISE_EXCEPTIONS=False in your settings:

ALGOLIA = {
    'APPLICATION_ID': 'MyAppID',
    'API_KEY': 'MyApiKey',
    'RAISE_EXCEPTIONS': False
}

I'll close this feature request as the feature is already implemented, and will improve its documentation in the readme. Let me know if this works for you!

PLNech commented 6 years ago

Documented in 7ce0caffee5c8cb5880439b6cbc275691f5a4afd.