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

sync_git crashes when importing snippet translations that are too long #426

Closed
TheoChevalier opened this issue Jun 25, 2021 · 2 comments · Fixed by #427
Closed

sync_git crashes when importing snippet translations that are too long #426

TheoChevalier opened this issue Jun 25, 2021 · 2 comments · Fixed by #427

Comments

@TheoChevalier
Copy link

sync_git crashes when importing a snippet translation that’s too long django.db.utils.DataError: value too long for type character varying(140)
Pretty sure the crash is due to this limit & me pushing a translation that’s going over

theochevalier@MBP:foundation.mozilla.org (localize-pni-products)$ heroku run --app=foundation-localize python network-api/manage.py sync_git
Running python network-api/manage.py sync_git on ⬢ foundation-localize... up, run.9824 (Hobby)
Generating SSH config
Done!
/app/.heroku/python/lib/python3.7/site-packages/environ/environ.py:630: UserWarning: /app/network-api/networkapi/.env doesn't exist - if you're not configuring your environment separately, create one.
  "environment separately, create one." % env_file)
System check identified some issues:

WARNINGS:
?: (urls.W002) Your URL pattern '/' [name='dashboard'] has a route beginning with a '/'. Remove this slash as it is unnecessary. If this pattern is targeted in an include(), ensure the include() pattern has a trailing '/'.
INFO - Pulling repository
INFO - Pull: Importing changes in file 'locales/de/pages/homepage/blog/basics-microtargeting-and-political-ads-facebook.po'
INFO - Pull: Importing changes in file 'locales/de/pages/homepage/blog/ring-2fa-and-win-consumers.po'
INFO - Pull: Importing changes in file 'locales/de/pages/homepage/blog/thank-you-apple-for-standing-strong-for-privacy.po'
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "https://www.youtube.com/embed/oN_kacGveQE?rel=0&cc_load_policy=1" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "https://www.youtube.com/embed/oN_kacGveQE?rel=0?cc_load_policy=1" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214503/twitter" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214269/twitter" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214504/facebook" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214270/facebook" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214506/email" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "http://share.mozilla.org/352/214271/email" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
INFO - Pull: Importing changes in file 'locales/de/pages/homepage/blog/youtube-regrets.po'
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "https://forms.gle/nzPTqRN6yVfrrnL58" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "https://forms.gle/pnC2sSjyQnidApdi6" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
/app/.heroku/python/lib/python3.7/site-packages/bs4/__init__.py:389: UserWarning: "https://foundation.mozilla.org/newsletter/" looks like a URL. Beautiful Soup is not an HTTP client. You should probably use an HTTP client like requests to get the document behind the URL, and feed that document to Beautiful Soup.
  ' that document to Beautiful Soup.' % decoded_markup
INFO - Pull: Importing changes in file 'locales/de/snippets/wagtailpages.Petition/16-let-us-be-part-of-the-hearing-petition.po'
INFO - Pull: Importing changes in file 'locales/de/snippets/wagtailpages.Petition/21-eu-misinformation-snippet.po'
INFO - Pull: Importing changes in file 'locales/de/snippets/wagtailpages.Petition/24-apple-rotate-tracking-ids-on-iphone-each-month.po'
INFO - Pull: Importing changes in file 'locales/de/snippets/wagtailpages.Petition/78-nextdoor-police-petition.po'
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(140)


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

Traceback (most recent call last):
  File "network-api/manage.py", line 34, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize_git/management/commands/sync_git.py", line 19, in handle
    SyncManager(logger=logger).sync()
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize_git/sync.py", line 165, in sync
    _pull(repo, self.logger)
  File "/app/.heroku/python/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize_git/sync.py", line 39, in _pull
    importer.import_resource(translation, po)
  File "/app/.heroku/python/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize_git/importer.py", line 29, in import_resource
    translation.save_target()
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize/models.py", line 1131, in save_target
    self.source.create_or_update_translation(self.target_locale, user=user, publish=publish, fallback=True, copy_parent_pages=True)
  File "/app/.heroku/python/lib/python3.7/site-packages/wagtail_localize/models.py", line 726, in create_or_update_translation
    translation.save()
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/base.py", line 754, in save
    force_update=force_update, update_fields=update_fields)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/base.py", line 792, in save_base
    force_update, using, update_fields,
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/base.py", line 873, in _save_table
    forced_update)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/base.py", line 926, in _do_update
    return filtered._update(values) > 0
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py", line 803, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1522, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.7/site-packages/sentry_sdk/integrations/django/__init__.py", line 489, in execute
    return real_execute(self, sql, params)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(140)

Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
@TheoChevalier
Copy link
Author

Found the offender and pushed a shorter translation, sync_git now runs correctly.

@kaedroho
Copy link
Contributor

Thanks for reporting! Yep, it looks like it's hitting that max length constraint at the database level. Wagtail would normally run this validation for pages in .save() but we've got to run this manually for snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants