processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

Querying users by "not default language" shows some inconsistencies

Open adrianbj opened this issue 4 years ago • 10 comments

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. image

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 avatar Dec 10 '20 04:12 adrianbj

@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 avatar Jan 12 '21 16:01 ryancramerdesign

@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.

adrianbj avatar Jan 13 '21 05:01 adrianbj

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.

ryancramerdesign avatar Aug 04 '21 16:08 ryancramerdesign

@adrianbj, how do you find Ryan's answer? Can we close this issue?

matjazpotocnik avatar Jul 18 '23 06:07 matjazpotocnik

@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.

adrianbj avatar Jul 18 '23 12:07 adrianbj

If it's not fixed, I won't close.

matjazpotocnik avatar Jul 18 '23 16:07 matjazpotocnik

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 :)

image

adrianbj avatar Jul 18 '23 16:07 adrianbj

Thanks for the followup!

matjazpotocnik avatar Jul 18 '23 16:07 matjazpotocnik

@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?

BernhardBaumrock avatar Jul 19 '23 08:07 BernhardBaumrock

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 :)

adrianbj avatar Jul 28 '23 18:07 adrianbj