processwire-issues
processwire-issues copied to clipboard
Querying users by "not default language" shows some inconsistencies
Short description of the issue
$users->find('language!=default') should only return users which have a non-default language, but it returns some users that are set to the default language.
Optional: Screenshots/Links that demonstrate the issue
Your screenshots/links go here.

Optional: Suggestion for a possible fix
Not really sure what's going on here - I thought maybe it was an issue for users that were set up (and last saved) before languages were enabled, but that's not the case. To "fix" these users, I had to change them to a different language, save them, and then change back to default and save again.
The key thing though is that the field_language DB table does not have an entry for them, so that's the issue, but I don't know how it happened in the first place.
@adrianbj You've got some users that have never been saved with a language selection, so we assume they should be default, but technically we don't know for certain. All we know is they have no language selection, so that's what you have to query in your case. The ones your selector is finding are those that have been saved with default selected. If I understand your need correctly, the first thing is that you want to find users that have a language selection, so you'd need language.id>0. Next you want to find users that do not have 'default' selected as the language name, so you'd want language.name!=default. Combined that would be language.id>0, language.name!=default.
@ryancramerdesign - I guess I don't understand why PW returns "default" for these users when calling $user->language - yes you are assuming because you don't know, but why can't the same logic hold for the language!=default find query? To me it would make sense to make the same assumption in both scenarios.
I guess I don't understand why PW returns "default" for these users when calling $user->language - yes you are assuming because you don't know, but why can't the same logic hold for the language!=default find query?
@adrianbj The default language is substituted as a fallback if no language is present, and this is something that happens at runtime, in memory, not in the database. When you do a find() you are querying the data in the database, rather than something that has been created at runtime for the current request.
@adrianbj, how do you find Ryan's answer? Can we close this issue?
@matjazpotocnik - personally I still think there is an inconsistency that needs addressing - how can I find users that don't have language set to default, but then when I get their language it returns default - it just doesn't compute :)
But at this point, I don't expect it will be addressed, so if you want to close it that's fine.
If it's not fixed, I won't close.
Just as a follow up, here's a current example. The problem is that Ryan does seem to think that this is expected, so not sure if he is willing to change it. I understand where he is coming from, but I don't agree with it, but that's OK :)
Thanks for the followup!
@adrianbj I understand your issue and I agree that it is an issue. On the other hand I also understand what Ryan said about a similar issue lately and I also agree with him: https://github.com/processwire/processwire-issues/issues/1783#issuecomment-1634348463
Does that comment also answer your question or is your use case / request different?
Hi @BernhardBaumrock - I think personally I would rather see PW ensure that all users have the default language set (if not another one). This issue kind of reminds me of this one: https://github.com/processwire/processwire-issues/issues/1310
It's these sorts of inconsistencies that can waste hours of time and hair loss :)