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

[Bug]: Inconsistent behavior on undefined post langagues during creation vs editing #4971

Open
5 tasks done
Nothing4You opened this issue Aug 11, 2024 · 0 comments
Open
5 tasks done
Labels
area: language-handling bug Something isn't working

Comments

@Nothing4You
Copy link
Contributor

Requirements

  • Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • Did you check to see if this issue already exists?
  • Is this only a single bug? Do not put multiple bugs in one issue.
  • Do you agree to follow the rules in our Code of Conduct?
  • Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.

Summary

Start by having no intersection in community allowed languages and user languages or two or more non-undetermined languages as intersection. The test community must not have Undetermined as allowed language.

When creating a new post, for example in Lemmy-UI, no language id is passed in the request body if no language is selected by the user.
Lemmy first checks if the provided language is acceptable. If no language is provided, this check simply returns success.
Next, Lemmy will determine the default post language to use. It will query the community languages and user languages and use the intersection if there is a single language that is not Undetermined or the non-undetermined language if the intersection is Undetermined and one other language. If no language could be found, the language id will not be passed to the DB and the column default of 0, which maps to Undetermined.
Based on this logic, it is clear that it should always be possible to create a post with Undetermined language.

When updating the post however, Lemmy-UI explicitly includes the Undefined as language id. Since this was returned by the server, it should be safe to assume that a post could be saved with the same value again, but Lemmy now raises a LanguageNotAllowed error.
The logic to update a post is quite similar to the creation, although the fallback to determine a default language is not present. Instead, this only checks if the provided language id, if one is provided, is allowed in the community.
Unlike during post creation, Lemmy-UI will now send the language id previously provided by the server, and the Undetermined language will now fail the test. This time the check will fail, as Undetermined is not None, and Undetermined is not an allowed language in the community.

What do you think about just updating is_allowed_community_language() to always return Ok(()) when for_language_id is UNDETERMINED_ID?

Steps to Reproduce

  1. Set community languages to Afaraf and avesta
  2. Set user language to Afrikaans
  3. Create post without selecting a language
{"name":"testfoo","community_id":1510682,"nsfw":false}
  1. Try editing the post without changing the language
{"post_id":2083355,"name":"testfoo","body":"1","nsfw":false,"language_id":0}
  1. Receive
{"error":"language_not_allowed"}

Technical Details

see above

Version

0.19.6-beta.4

Lemmy Instance URL

voyager.lemmy.ml

@Nothing4You Nothing4You added the bug Something isn't working label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: language-handling bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants