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

'disable_auto_indexing()' connects receiver even if AUTO_INDEXING is False #286

Open
kasai-mitsuru opened this issue Nov 20, 2019 · 1 comment

Comments

@kasai-mitsuru
Copy link

kasai-mitsuru commented Nov 20, 2019

  • Django version: 2.2.1
  • Algolia Django integration version: 1.7.1
  • Algolia Client Version: 1.20.0
  • Language Version: Python 3.6.8

Description

disable_auto_indexing() in decorators.py makes connection even if AUTO_INDEXING = False .

In AUTO_INDEXING = False environment, once disable_auto_indexing() is called, AlgoliaEngine will try to index when model saving.

    def __exit__(self, exc_type, exc_value, traceback):
        for model in self.models:
            post_save.connect(
                algolia_engine._AlgoliaEngine__post_save_receiver,
                sender=model
            )
            pre_delete.connect(
                algolia_engine._AlgoliaEngine__pre_delete_receiver,
                sender=model
            )

I think it needs condition if AUTO_INDEXING is True, like bellow.

    def __exit__(self, exc_type, exc_value, traceback):
        if some_auto_indexing  # this
    	    for model in self.models:
        	    post_save.connect(
            	    algolia_engine._AlgoliaEngine__post_save_receiver,
                	sender=model
           		)
           		pre_delete.connect(
           		    algolia_engine._AlgoliaEngine__pre_delete_receiver,
           		    sender=model
           		)

Steps To Reproduce

settings.py

ALGOLIA = {"APPLICATION_ID": "foo", "API_KEY": "bar", "AUTO_INDEXING": False}

index.py

@register(SomeModel)
class SomeModelIndex():
	...

sample.py

from algoliasearch_django.decorators import disable_auto_indexing
with disable_auto_indexing():
	pass
SomeModel().save()  # -> Error will be Occured

a part of error message

algoliasearch.helpers.AlgoliaException: Unreachable hosts: {'foo.algolia.net': "ConnectionError: HTTPSConnectionPool(host='foo.algolia.net', port=443): Max retries exceeded with url: /1/indexes/SomeModel/236 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f126590d550>: Failed to establish a new connection: [Errno -2] Name or service not known',))", 'foo-1.algolianet.com': "ConnectionError: HTTPSConnectionPool(host='foo-1.algolianet.com', port=443): Max retries exceeded with url: /1/indexes/SomeModel/236 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1265941da0>: Failed to establish a new connection: [Errno -2] Name or service not known',))", 'foo-3.algolianet.com': "ConnectionError: HTTPSConnectionPool(host='foo-3.algolianet.com', port=443): Max retries exceeded with url: /1/indexes/SomeModel/236 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f126590dc88>: Failed to establish a new connection: [Errno -2] Name or service not known',))", 'foo-2.algolianet.com': "ConnectionError: HTTPSConnectionPool(host='foo-2.algolianet.com', port=443): Max retries exceeded with url: /1/indexes/SomeModel/236 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f12656d8208>: Failed to establish a new connection: [Errno -2] Name or service not known',))"}
@tkrugg
Copy link
Contributor

tkrugg commented Jan 26, 2021

Hi @kasai-mitsuru that's a great point!
I see another problem with this API: it's disabling indexing over all the models whilst giving the illusion it's only affecting the scope it's encapsulating. This whole API should be re-engineered into something more flexible that can enable/disable indexing on specific registrations.

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

No branches or pull requests

2 participants