question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not import aldryn_search outside PostIndex in search_indexes.py

See original GitHub issue

Description

We’re not using aldryn_search at all, but we’re using django-haystack in order to index elements of our websites. We had installed djangocms_blog.

Haystack allows to exclude Indexes with its EXCLUDED_INDEXES paremeter, but it only excludes the content of the Index class.

The problem here is that you include aldryn_search submodules outside the PostIndex, and so when I prevent your search_indexes.py from being used by haystack using "EXCLUDED_INDEXES": ["djangocms_blog.search_indexes.PostIndex"],, it always try to import aldryn_search, even without using your PostIndex at all.

https://github.com/nephila/djangocms-blog/blob/99ab6a1be8a930972d9712321a17ac67a2354bab/djangocms_blog/search_indexes.py#L1-L2

Steps to reproduce

  • Do not install aldryn_search.
  • Try to index something on the project using django-haystack, but not djangocms_blog (thanks to "EXCLUDED_INDEXES": ["djangocms_blog.search_indexes.PostIndex"],).
  • Exception:
    File "[...]djangocms_blog/search_indexes.py", line 4, in <module>
       from aldryn_search.helpers import get_plugin_index_data
    ModuleNotFoundError: No module named 'aldryn_search'
    

Expected solution

Move lines aldryn_search imports in search_indexes.py inside the class: https://github.com/nephila/djangocms-blog/blob/99ab6a1be8a930972d9712321a17ac67a2354bab/djangocms_blog/search_indexes.py#L11

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yakkycommented, Jun 21, 2020

@corentinbettiol definitely nothing wrong! Thanks for reviewing it, I amended the documentation as suggested

0reactions
corentinbettiolcommented, Jun 15, 2020

@yakky Done. I think it’s my first review, I don’t really know if I did anything wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python import: Advanced Techniques and Tips
The Python import system is as powerful as it is useful. In this in-depth tutorial, you'll learn how to harness this power to...
Read more >
importlib — The implementation of import — Python 3.11.1 ...
This is useful if you have edited the module source file using an external editor and want to try out the new version...
Read more >
What does __all__ mean in Python? - Stack Overflow
Members that are not mentioned in __all__ are still accessible from outside the module and can be imported with from <module> import <member>...
Read more >
Python – Import module from different directory - GeeksforGeeks
Now don't worry if your module is not imported correctly. In this article, we will discuss ways to import a module from another...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found