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

'str' object does not support item assignment #7294

Closed
2 tasks done
JohnRDOrazio opened this issue Feb 23, 2022 · 19 comments · Fixed by translate/translate#4579
Closed
2 tasks done

'str' object does not support item assignment #7294

JohnRDOrazio opened this issue Feb 23, 2022 · 19 comments · Fixed by translate/translate#4579
Assignees
Labels
translate-toolkit Issues which need to be fixed in the translate-toolkit
Milestone

Comments

@JohnRDOrazio
Copy link
Contributor

JohnRDOrazio commented Feb 23, 2022

Describe the issue

When trying to commit changes for a component with a nested JSON format, I am getting an exception and the commits are not pushed to github.

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

I have a feeling it may have to do with the fact that I'm using a nested array in the JSON source file. I know that arrays will work fine under an object key or property, but perhaps a nested array will cause problems?

  1. Go to Manage -> Repository Maintenance and click on Commit

Expected behavior

Commits should be successful and pushed to the github repo.

Screenshots

No response

Exception traceback

Traceback (most recent call last):
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response =3D get_response(request)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response =3D wrapped_callback(request, *callback_args, **callback_kwarg=
s)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_v=
iew
    return view_func(request, *args, **kwargs)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/views/git.py", line 138, in commit_component
    return perform_commit(request, obj)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/views/git.py", line 54, in perform_commit
    return execute_locked(
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/views/git.py", line 35, in execute_locked
    result =3D call(*args, **kwargs)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/models/component.py", line 157, in on_link_w=
rapper
    return func(self, *args, **kwargs)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/models/component.py", line 1583, in commit_p=
ending
    translation.commit_pending(reason, user, skip_push=3DTrue, signals=3DFa=
lse)
  File "/usr/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/models/translation.py", line 590, in commit_=
pending
    self.update_units(units, store, author_name, author.id)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/trans/models/translation.py", line 773, in update_=
units
    store.save()
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/formats/ttkit.py", line 306, in save
    self.save_atomic(self.storefile, self.save_content)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/formats/base.py", line 324, in save_atomic
    callback(temp)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/weblate/formats/ttkit.py", line 302, in save_content
    self.store.serialize(handle)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/translate/storage/jsonl10n.py", line 173, in serialize
    self.serialize_units(units)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/translate/storage/base.py", line 1008, in serialize_units
    unit.storevalues(output)
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/translate/storage/jsonl10n.py", line 246, in storevalues
    self.storevalue(output, self.converttarget())
  File "/var/www/vhosts/johnromanodorazio.com/weblate/translate/lib/python3=
.8/site-packages/translate/storage/base.py", line 982, in storevalue
    target[key] =3D value

How do you run Weblate?

PyPI module

Weblate versions

  • Weblate: 4.10.1
  • Django: 3.2.5
  • siphashc: 2.1
  • translate-toolkit: 3.5.1
  • lxml: 4.6.3
  • Pillow: 8.2.0
  • bleach: 3.3.1
  • python-dateutil: 2.8.2
  • social-auth-core: 4.1.0
  • social-auth-app-django: 5.0.0
  • django-crispy-forms: 1.11.2
  • oauthlib: 3.1.1
  • django-compressor: 2.4.1
  • djangorestframework: 3.12.4
  • django-filter: 2.4.0
  • django-appconf: 1.0.4
  • user-agents: 2.2.0
  • filelock: 3.0.12
  • setuptools: 44.0.0
  • jellyfish: 0.8.2
  • openpyxl: 3.0.7
  • celery: 5.0.5
  • kombu: 5.1.0
  • translation-finder: 2.9
  • weblate-language-data: 2021.5
  • html2text: 2020.1.16
  • pycairo: 1.20.1
  • pygobject: 3.40.1
  • diff-match-patch: 20200713
  • requests: 2.25.1
  • django-redis: 4.12.1
  • hiredis: 2.0.0
  • sentry_sdk: 1.1.0
  • Cython: 0.29.24
  • misaka: 2.1.1
  • GitPython: 3.1.18
  • borgbackup: 1.1.17
  • pyparsing: 3.0.6
  • pyahocorasick: 1.4.2
  • python-redis-lock: 3.7.0
  • Python: 3.8.10
  • Git: 2.25.1
  • psycopg2-binary: 2.8.6
  • phply: 1.2.5
  • chardet: 4.0.0
  • ruamel.yaml: 0.17.16
  • tesserocr: 2.5.2
  • akismet: 1.1
  • boto3: 1.17.112
  • zeep: 4.0.0
  • aeidon: 1.9
  • iniparse: 0.5
  • mysqlclient: 2.0.3
  • Mercurial: 5.8.1
  • git-svn: 2.25.1
  • git-review: 2.1.0
  • Redis server: 5.0.7
  • PostgreSQL server: 12.9
  • Database backends: django.db.backends.postgresql
  • Cache backends: default:RedisCache, avatar:FileBasedCache
  • Email setup: django.core.mail.backends.smtp.EmailBackend: mail.johnromanodorazio.com
  • OS encoding: filesystem=utf-8, default=utf-8
  • Celery: redis+socket:///var/run/redis/redis-server.sock?db=1, redis+socket:///var/run/redis/redis-server.sock?db=1, regular
  • Platform: Linux 5.4.0-73-generic (x86_64)

Weblate deploy checks

System check identified some issues:

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-4.10.1/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-4.10.1/admin/backup.html

System check identified 2 issues (1 silenced).

Additional context

No response

@JohnRDOrazio
Copy link
Contributor Author

If the email with the traceback and the state of variables at time of the exception can be useful, here is a PDF of the email...
[Weblate] ERROR (EXTERNAL IP) Internal Server Error.pdf

@nijel
Copy link
Member

nijel commented Feb 23, 2022

It should work. I've added some tests in translate/translate#4578. What is existing content of the English JSON file (only the portion of story_9795.tsr_0 is interesting here)?

@nijel nijel added the translate-toolkit Issues which need to be fixed in the translate-toolkit label Feb 23, 2022
@github-actions
Copy link

The issue you've reported needs to be addressed in the translate-toolkit. Please file the issue there, and include links to any relevant specifications about the formats (if applicable).

nijel added a commit to translate/translate that referenced this issue Feb 23, 2022
@JohnRDOrazio
Copy link
Contributor Author

The source in this case is Italian, and here is story_9795:

    "story_9795": {
        "tsr_0": [
            [
                "",
                "Combinato Carcer Tullianum & parco"
            ],
            "Archeologico del Colosseo"
        ]

@JohnRDOrazio
Copy link
Contributor Author

In my application code, I am using some placeholders for special characters (I am creating an extendscript plugin for Indesign to extract strings from an Indesign file, translate them, and import them back into Indesign). In the application code, when importing the translations back into Indesign, I am first checking if there is a nested array, and I deal with that first, replacing any special characters back to the originals. Once I have flattened to a simple array, I then join the array with a paragraph separator character (each element of the array is a separate paragraph, even though it belongs to the same "story").

@JohnRDOrazio
Copy link
Contributor Author

JohnRDOrazio commented Feb 23, 2022

I tried manually applying the patch in commit 3ae20f394b4d86d79167ce7694b56dc288b079c2 , however after restarting my uwsgi service I am still getting the same error.

@nijel
Copy link
Member

nijel commented Feb 23, 2022

That commit was not expected to address your issue, it covers a different issue.

The issue might be in mixing list and string in the list, the code might assume that all types will be same. I will verify this assumption tomorrow...

@nijel
Copy link
Member

nijel commented Feb 24, 2022

The source in this case is Italian

The current content of English file is probably what causes the problems, please share that one.

@JohnRDOrazio
Copy link
Contributor Author

JohnRDOrazio commented Feb 24, 2022

It seems the English file needs to be updated based on the Italian source file. There is no "story_9795" key in the English file. Here is a link to the file: https://github.com/opera-romana-pellegrinaggi/catalogo-v-r-test/blob/main/en/translation.json .

I have activated the Cleanup translation files plugin, but it doesn't seem to be succeeding in this case.

@nijel nijel self-assigned this Feb 24, 2022
@nijel nijel added this to the 4.11 milestone Feb 24, 2022
nijel added a commit to nijel/translate that referenced this issue Feb 24, 2022
When the units are not added in the order of serializing, the lists can
have blank space which needs to be filled in with None.

This fixes list ordering for newly added strings.

Fixes WeblateOrg/weblate#7294
nijel added a commit to nijel/translate that referenced this issue Feb 24, 2022
When the units are not added in the order of serializing, the lists can
have blank space which needs to be filled in with None.

This fixes list ordering for newly added strings.

Fixes WeblateOrg/weblate#7294
@nijel
Copy link
Member

nijel commented Feb 24, 2022

Cleanup won't help with this (it removes stale strings, it does not help in adding new ones).

translate/translate#4579 should fix this.

nijel added a commit to translate/translate that referenced this issue Feb 24, 2022
When the units are not added in the order of serializing, the lists can
have blank space which needs to be filled in with None.

This fixes list ordering for newly added strings.

Fixes WeblateOrg/weblate#7294
@github-actions
Copy link

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

@JohnRDOrazio
Copy link
Contributor Author

Fix is working! I was able to successfully commit

@iksent
Copy link

iksent commented Jul 7, 2022

Hello!
I am experiencing most likely the same issue.
Updating Weblate to the latest 4.13.1 didn't help.

Getting error at Email trying to commit many changes:

Django Version: | 4.0.5
-- | --
TypeError
'str' object does not support item assignment
/usr/local/lib/python3.10/site-packages/translate/storage/base.py, line 1000, in storevalue
/usr/local/bin/python
3.10.5
['/',  '/usr/local/lib/python3.10/site-packages/git/ext/gitdb',  '/',  '/usr/local/bin',  '/usr/local/lib/python310.zip',  '/usr/local/lib/python3.10',  '/usr/local/lib/python3.10/lib-dynload',  '/usr/local/lib/python3.10/site-packages',  '/app/data/python',  '/usr/local/lib/python3.10/site-packages/gitdb/ext/smmap']
Thu, 07 Jul 2022 10:56:59 +0000

@nijel
Copy link
Member

nijel commented Jul 7, 2022

@iksent Did you update translate-toolkit as well? In case you did, please include a full exception traceback and open a separate issue.

@iksent
Copy link

iksent commented Jul 7, 2022

We use weblate docker image, should we update it anyway? And how to do this?

@iksent
Copy link

iksent commented Jul 7, 2022

The problem, is that we manually set incorrect JSON as a default template with empty strings.

{ key: "" } instead of { key: [] }

@nijel
Copy link
Member

nijel commented Jul 7, 2022

Please open separate issue for that.

@iksent
Copy link

iksent commented Jul 7, 2022

OK, I'll try to do that later. We are trying to resolve this issue now, can you please help?

  • We couldn't Commit as error appears
  • and couldn't Update by deleting default file as error appears again
  • and couldn't Export the result file as exporting from memory generates system JSON file...

What should we do to apply changes?

@iksent
Copy link

iksent commented Jul 7, 2022

We found a solution: create new component and migrate translations there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translate-toolkit Issues which need to be fixed in the translate-toolkit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants