# Patch updates to a log by a user with non-default language fail w/ 405

**URL:** <https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473>\
**Category:** Development\
**Tags:** support-request\
**Created:** [January 12, 2023, 8:11am UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473 "2023-01-12T08:11:35Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 4:37pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/22 "2023-01-16T16:37:21Z")

</div>

OK, interesting! Thanks for these clues @Farmer-Ed and @pat. It makes me wonder if maybe the `langcode` is being saved to the log as `en`/`no` depending on what language the user is using when they save it? But then the API is trying to save it as the opposite, or something…

Are you creating AND updating the log both through the API? Or was it created through the UI and then being updated through the API? (Or some other combination of things?)

---

<div class="post-metadata">

**Author:** ![pat](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/pat/32/1050_2.png) [@pat](https://farmos.discourse.group/u/pat)\
**Post date:** [January 16, 2023, 4:43pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/23 "2023-01-16T16:43:15Z")

</div>

> [@mstenta](#):
>
> Are you creating AND updating the log both through the API? Or was it created through the UI and then being updated through the API? (Or some other combination of things?)

All is done through API from Node-Red.

I could try to patch a log created in the UI

---

<div class="post-metadata">

**Author:** ![pat](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/pat/32/1050_2.png) [@pat](https://farmos.discourse.group/u/pat)\
**Post date:** [January 16, 2023, 4:50pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/24 "2023-01-16T16:50:30Z")

</div>

Result:

Created in UI, EN - change to NO - PATCH = error 405  
Created in UI, NO - no change - PATCH = error 405

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 5:00pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/25 "2023-01-16T17:00:54Z")

</div>

> [@Farmer-Ed](#):
>
> @pat try setting your users language to English and try again.

What happens when you do this @pat? Change your user’s language to EN and then try PATCH.

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 5:01pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/26 "2023-01-16T17:01:28Z")

</div>

Oh wait you already did that above, and it worked… 😄

> [@pat](#):
>
> Well, that worked

---

<div class="post-metadata">

**Author:** ![pat](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/pat/32/1050_2.png) [@pat](https://farmos.discourse.group/u/pat)\
**Post date:** [January 16, 2023, 6:16pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/27 "2023-01-16T18:16:48Z")

</div>

Yep.  
Patching with norwegian user don’t

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 6:39pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/28 "2023-01-16T18:39:56Z")

</div>

Found this: [https://www.drupal.org/project/drupal/issues/3043168](https://www.drupal.org/project/drupal/issues/3043168)

Reading through it now to see if I can find any potential clues…

One thing that would be useful @pat … could you paste the JSON representation of the log you are trying to PATCH? Or at least the top bit (don’t need all the `attributes` and `relationships` I don’t think).

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 6:49pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/29 "2023-01-16T18:49:38Z")

</div>

Here is the line in the Drupal core JSON:API module that produces the error: [core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php · b9b6fa58648511a957d3dc82bd017a008885b6e7 · project / drupal · GitLab](https://git.drupalcode.org/project/drupal/-/blob/b9b6fa58648511a957d3dc82bd017a008885b6e7/core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php#L72)

The condition is pretty simple, so I bet we can figure out what’s failing…

```auto
if ($method === 'PATCH' && $entity->language()->getId() !== $current_content_language) {
  $available_translations = implode(', ', array_keys($entity->getTranslationLanguages()));
  throw new MethodNotAllowedHttpException(['GET'], sprintf('The requested translation of the resource object does not exist, instead modify one of the translations that do exist: %s.', $available_translations));
}

```

Right above that `$current_content_language` gets set:

```auto
$current_content_language = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();

```

I can run that same code via Drush to see what it returns…

`drush php-eval "print(\Drupal::service('language_manager')->getCurrentLanguage('language_content')->getId());"`

@pat On your instance that returns `nb`.

I’m curious what `$entity->language()->getId()` is… I’m guessing `en`… @pat (or @Farmer-Ed) could you confirm what the `langcode` is on the log before you try to `PATCH` it?

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 6:51pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/30 "2023-01-16T18:51:26Z")

</div>

> [@mstenta](#):
>
> Found this: [Client Challenge](https://www.drupal.org/project/drupal/issues/3043168)

Ah ha looks like @Farmer-Ed beat me to this up above. 😅

> [@Farmer-Ed](#):
>
> It could be a bug with translated sites:

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 6:53pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/31 "2023-01-16T18:53:30Z")

</div>

> [@mstenta](#):
>
> I’m curious what `$entity->language()->getId()` is… I’m guessing `en`…

Assuming this is the case…

> [@mstenta](#):
>
> @pat On your instance that returns `nb`.

… that would cause the issue.

So maybe the question is: why is `$current_content_language` set to `nb`? Maybe that should always be `en` if we aren’t using the content translation module? Perhaps the `farm_l10n` module could force that?

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 6:59pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/32 "2023-01-16T18:59:43Z")

</div>

This is insightful: [https://www.drupal.org/project/drupal/issues/2794431](https://www.drupal.org/project/drupal/issues/2794431)

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 7:03pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/33 "2023-01-16T19:03:27Z")

</div>

@pat One idea for a workaround while we continue to investigate this… I think if you created a dedicated API user in your instance, with a language of English, you could use that for API requests and it would work.

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 7:09pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/34 "2023-01-16T19:09:20Z")

</div>

> [@mstenta](#):
>
> This is insightful: [Client Challenge](https://www.drupal.org/project/drupal/issues/2794431)

This is interesting, and suggests that Drupal core is still working through all the different ways that JSON:API could/should work with translations. This sums it up:

> The problem with this is that it depends on and varies by each site’s language negotiation configuration. This means translations may behave differently on Drupal-powered JSON:API instances A versus B.

I think that’s basically what we’re running into here. Although I’m curious if we can solve this with a simple hack/override in `farm_l10n`… with the understanding/assumption that farmOS does NOT support support content translations and the default language is always `en`. Like I said above…

> [@mstenta](#):
>
> Maybe that should always be `en` if we aren’t using the content translation module? Perhaps the `farm_l10n` module could force that?

These assumptions may not be “forever”, though, so would this create roadblocks for some of those next steps… ? Seems like they would.

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 16, 2023, 7:12pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/35 "2023-01-16T19:12:31Z")

</div>

> [@mstenta](#):
>
> so would this create roadblocks for some of those next steps… ?

Specifically by “next steps” I mean:

- Allowing other languages to be the “default” (referring specifically to what was decided upon here, which refers to a very specific configuration, mind you: [Client Challenge](https://www.drupal.org/project/farm/issues/3257430))
- Allowing use of the content translation modules.

Neither of those are priorities for future farmOS development, so it would only be creating roadblocks for developers/hackers who wanted to go farther on their own.

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [January 16, 2023, 7:13pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/36 "2023-01-16T19:13:31Z")

</div>

> [@mstenta](#):
>
> I’m curious what `$entity->language()->getId()` is… I’m guessing `en`… @pat (or @Farmer-Ed) could you confirm what the `langcode` is on the log before you try to `PATCH` it?

All of mine would have been `en`, as I created the data before adding the new language.

---

<div class="post-metadata">

**Author:** ![pat](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/pat/32/1050_2.png) [@pat](https://farmos.discourse.group/u/pat)\
**Post date:** [January 16, 2023, 9:19pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/37 "2023-01-16T21:19:41Z")

</div>

> [@mstenta](#):
>
> One thing that would be useful @pat … could you paste the JSON representation of the log you are trying to PATCH?

Here:

```auto
msg.payload = {
    "data": {
        "type": "log--lab_test",
        "attributes": {
            "name": "Jordprøve",
            "status": "pending",
            "notes": "",
            "lab_test_type": "soil"
        }
    }
}

```

The above log created with Norwegian user:

```auto
langcode : "en"

```

---

<div class="post-metadata">

**Author:** ![pat](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/pat/32/1050_2.png) [@pat](https://farmos.discourse.group/u/pat)\
**Post date:** [January 16, 2023, 9:21pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/38 "2023-01-16T21:21:41Z")

</div>

Also

```auto
default_langcode : true

```

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [January 17, 2023, 7:40am UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/39 "2023-01-17T07:40:26Z")

</div>

I think he means the stored JSON

```auto
{
	"type": "log--lab_test",
	"id": "03979e6e-e6e6-44a9-8581-5a6ace4eec99",
	"links": {
		"self": {
			"href": "http://192.168.1.18/api/log/lab_test/03979e6e-e6e6-44a9-8581-5a6ace4eec99?resourceVersion=id%3A374"
		}
	},
	"attributes": {
		"drupal_internal__id": 243,
		"drupal_internal__revision_id": 374,
		"langcode": "en",
		"revision_created": "2023-01-16T15:50:18+00:00",
		"revision_log_message": null,
		"name": "Jordprøve",
		"timestamp": "2023-01-15T15:53:18+00:00",
		"status": "done",
		"created": "2023-01-15T15:53:18+00:00",
		"changed": "2023-01-16T14:49:55+00:00",
		"default_langcode": true,
		"revision_translation_affected": null,
		"data": null,
		"notes": null,
		"flag": [],
		"is_group_assignment": null,
		"geometry": null,
		"is_movement": false,
		"lab_test_type": null,
		"lab_received_date": null,
		"lab_processed_date": null
	}
}

```

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [January 17, 2023, 11:18am UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/40 "2023-01-17T11:18:09Z")

</div>

@mstenta  
I found something Interesting…

 ![image](https://global.discourse-cdn.com/free1/uploads/farm_os/original/2X/e/e74bfdeaf62d5248b013847ca9c6e914414376d1.png)

I think if you don’t support translations in content that you shouldn’t use the `"langcode": "en"` it should be `"langcode": "und"`

It works with Logs created through the API and UI and regardless of the Users Language.  
Not sure where the existing logs(and other entities?) would stand though if this change was made to existing sites? I can modify them manually one at a time from UI but get not allowed from API

zxx also seems to work as langcode

und = Not Specified  
zxx = Not Applicable

---

<div class="post-metadata">

**Author:** ![Symbioquine](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/symbioquine/32/284_2.png) [@Symbioquine](https://farmos.discourse.group/u/Symbioquine)\
**Post date:** [January 17, 2023, 4:46pm UTC](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473/41 "2023-01-17T16:46:01Z")

</div>

> [@Farmer-Ed](#):
>
> I think if you don’t support translations in content that you shouldn’t use the `"langcode": "en"` it should be `"langcode": "und"`

This seems like the right answer to me. It would let us punt on the whole concept of “content language” until the desired behavior can be nailed down.

[Previous page](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473.md?page=1)

[Next page](https://farmos.discourse.group/t/patch-updates-to-a-log-by-a-user-with-non-default-language-fail-w-405/1473.md?page=3)
