-
Notifications
You must be signed in to change notification settings - Fork 79
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
Language detection fails #48
Comments
Hello Jakob, Just to make sure I understand, in your example above you expect the |
EDIT: I expect the EDIT 2: This only happens when publishing. I should read your post, before answering... Hi, this is exactly the case. The same applies for a blog post when going to the blog page in the primary langue, lets say Thanks for your quick reply Jakob |
So yes this is a problem I'm quite familiar with. And yes the only solution to this is to leverage In the past, I've defined the As far as a real solution comes, I've pushed a potential fix to the fixes/let-object-decide-alias branch. Please have a look at the branch and let me know if it works for you, I did a quick test locally and it worked. |
Thank you, I will check it out! |
I haven't tested the code, yet but from the looks this is what I imagined. However the line unified_index = connections[alias].get_unified_index() https://github.com/aldryn/aldryn-search/blob/fixes/let-object-decide-alias/aldryn_search/router.py#L32 looks suspicious to me, since we are trying to find the index of a potentially wrong connection (the What dou you think? Regards Jakob |
Your suspicion is accurate, haystack allows you to exclude indexes from certain connections and so it is possible that we fail to get an index for a connection but in my opinion it's better than getting the language wrong every time. I think a better solution would require a change in the way haystack triggers the object indexing (signal). Iterating over all connections is not a bad idea but I'm not really a fan of brute forcing it but it might be the way to go until a proper fix can be integrated in Haystack. I agree that the code is not very pretty because it exposes an internal logic in Haystack, but this is actually found everywhere there :) Regarding a potential for performance impact, it really depends. Currently there's none. Accessing a connection is just accessing a dictionary and never touching the search engine, after that we call the |
FYI, works for my use cases so far. Thank you very much Jakob |
Hey @czpython, what happened to the branch if I may politely inquire? Is there any way this will make it into a release? Realtime indexing is seriously broken without this fix... Thank you very much Jakob |
Hey @jakob-o, I meant to post an update here.. I closed the pr #49 (comment) and posted an explanation as to why I decided it's not the way to go. I have a fix for this issue on cms pages which I will push sometime this week. As far as other addons like Aldryn Newsblog go, I'll have to think of another solution 😢 |
EDIT: OK forget that we could use the function that I mentioned, but would there be a possibility to detect the publishing language another way? Hey @czpython, how about a middleware that stores the result from Regards Jakob |
Another possibility would be a registry, that allows language lookup based on the instance. Something like: def get_instance_language(instance):
try:
lookup = language_lookups[instance.__class__]
except KeyError:
return get_language()
else:
return lookup.get_language(instance) |
@jakob-o Thanks for the suggestions. I will be using the |
EDIT: I just realized the code changes in this repo were only for the unpublishing issue... My question remains though. EDIT2: Created a pull request #61 Hey @czpython, I had a look at the updated code and am not sure how this would solve the language detection problem. I am fine with it for now however (using a custom router implementing the registry approach). Two small things though:
The latter one would spare me a lot of trouble since I am using a custom implementation based on aldryn_search and https://github.com/django-haystack/celery-haystack which is adding an Thank you very much! Jakob |
Hello @jakob-o, I've not gotten around to implement the language fix yet.. Regarding your points:
|
How about |
Hi,
I am facing an issue when creating blog posts / publishing pages from the page listing in another language. The basic problem is, that
get_language()
returns the wrong value e.g. for this linkhttp://localhost:8000/en/admin/cms/page/13/de/publish/?redirect_language=en&redirect_page_id=5
. The same applies for blog posts.To clarify / how to reproduce:
Expected:
Actual:
I tried to workaround that by inspecting the instance in a custom implementation of the router, unfortunately there is not unified way to do so. The Title model for instance has a
language
attribute whilst an Article has alanguage_code
. The only solution for now that comes to my mind would be to store all entries in one index and query with a language filter...Any recommendations / help regarding this are greatly appreciated.
Regards
Jakob
The text was updated successfully, but these errors were encountered: