Closed psmyrek closed 2 years ago
@psmyrek The latest release fixes the issue.
Thank you for you feedback and the detailed steps.
I noticed that with the latest version of @transifex/api
(v7.1.1) I'm still able to trigger this error by saving the translation for a new ResourceTranslation. In my situation the error was that the translator
was null.
I followed the example here: https://github.com/transifex/transifex-javascript/tree/master/packages/api#changing-attributes
My code looks something like below.
I get the crash in _postSave
when it attempts to refresh the relations.
I'm able to work around the issue by assigning a dummy user to the 'translator' relationship.
// Our project doesn't have this language yet, create one
if (!supported.has(languageID)) {
await project.add('languages', [languages.get(languageID)]);
// After adding the language, we should get a collection of empty ResourceTranslations below.
}
// Get the ResourceTranslations (for new language, they are empty slots)
const results = [];
const iter = api.ResourceTranslation.filter({ resource: resourceID, language: languageID });
for await (const val of iter.all()) {
results.push(val);
}
// Try to update one.
const translation = results[0]
// weird: it will crash in `_postSave` looking for the `id` if we don't supply a translator here!
translation.set('translator', user);
translation.set('strings', { 'other': 'new string' });
await translation.save(['strings']);
Current Behavior I'm using
@transifex/api
v4.2.1 and I wanted to update one translation in my project by using this package, as described in the docs: https://github.com/transifex/transifex-javascript/tree/master/packages/api#changing-attributes. The translation is updated on Transifex side, but the.save()
method throws an error:TypeError: Cannot read property 'id' of null
.Some debug notes that might help you fixing this issue
The
_postSave()
method iterates over all entries and it tries to read theid
, but theid
for thereviewer
(which isnull
in my case) is not accessible. This is why it throws theTypeError: Cannot read property 'id' of null
error.Expected Behavior Updating the translation by using the
.save()
method should not throw an error, if nullable relationship isnull
.Steps to Reproduce Call the
translation.save()
method on a translation, that does not have a reviewer set (reviewer isnull
);Possible Solution Check the nullable relationships.