mozilla / wagtail-localize-smartling

Integration between wagtail-localize and Smartling's API
Mozilla Public License 2.0
1 stars 1 forks source link

Job syncing fails with NameError #8

Closed stevejalim closed 2 months ago

stevejalim commented 2 months ago

On 0.2.2, when running ./manage.py sync_smartling and there is a completed translation ready on the Smartling side to sync down, I am hitting this error (running locally)

ERROR 2024-07-04 07:45:31,183 sync_smartling Error syncing job with ID 6
Traceback (most recent call last):
  File "/Users/steve/.pyenv/versions/bedrock/lib/python3.11/site-packages/wagtail_localize_smartling/sync.py", line 75, in sync_job
    _sync(job)
  File "/Users/steve/.pyenv/versions/bedrock/lib/python3.11/site-packages/wagtail_localize_smartling/sync.py", line 171, in _sync
    _download_and_apply_translations(job)
  File "/Users/steve/.pyenv/versions/bedrock/lib/python3.11/site-packages/wagtail_localize_smartling/sync.py", line 231, in _download_and_apply_translations
    sender=Job,
           ^^^
NameError: name 'Job' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/steve/.pyenv/versions/bedrock/lib/python3.11/site-packages/wagtail_localize_smartling/management/commands/sync_smartling.py", line 27, in handle
    sync_job(job_id)
  File "/Users/steve/.pyenv/versions/3.11.3/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/steve/.pyenv/versions/bedrock/lib/python3.11/site-packages/wagtail_localize_smartling/sync.py", line 77, in sync_job
    raise SyncJobException(f"Exception syncing job {job}") from e
wagtail_localize_smartling.sync.SyncJobException: Exception syncing job 0b3dd32e-9557-44fd-b147-e38b0197a2f9:3:fr:2024-07-04T14:44:22+00:00

I can see that the Job class mentioned in the traceback is only present if we're in type-checking mode, rather than at runtime:

https://github.com/mozilla/wagtail-localize-smartling/blob/3b72cc94dbf5d132505b03a0ebe5c0a416e4b473/src/wagtail_localize_smartling/sync.py#L18-L19

stevejalim commented 2 months ago

Have made it work locally by tweaking it like this

https://github.com/mozilla/wagtail-localize-smartling/pull/9