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

Replacing links used in multiple pages causes internal server error #1696

Closed
Tracked by #1704
ulliholtgrave opened this issue Sep 17, 2022 · 1 comment
Closed
Tracked by #1704
Labels
wontfix This will not be worked on

Comments

@ulliholtgrave
Copy link
Member

ulliholtgrave commented Sep 17, 2022

Describe the Bug

If we want to edit links that are used in multiple pages, we might encounter a constraint violation of our database

I am not really sure if this is related to the archived pages or if this is also connected to the race conditions of #1518 .

Additional Information

Traceback
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/integreat_cms/cms/models/abstract_content_translation.py", line 487, in save
  super().save(*args, **kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 739, in save
  self.save_base(using=using, force_insert=force_insert,
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 776, in save_base
  updated = self._save_table(
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 881, in _save_table
  results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 919, in _do_insert
  return manager._insert(
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
  return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/query.py", line 1270, in _insert
  return query.get_compiler(using=using).execute_sql(returning_fields)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
  cursor.execute(sql, params)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/cacheops/transaction.py", line 98, in execute
  result = self._no_monkey.execute(self, sql, params)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
  return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
  return executor(sql, params, many, context)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
  return self.cursor.execute(sql, params)
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
  raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
  return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "pagetranslation_unique_version"
DETAIL:  Key (page_id, language_id, version)=(12473, 3, 17) already exists.
@ulliholtgrave ulliholtgrave added bug Something isn't working prio: high Needs to be resolved ASAP. labels Sep 17, 2022
@ulliholtgrave ulliholtgrave added this to the 22Q4 milestone Sep 17, 2022
@timobrembeck timobrembeck added effort: medium Should be doable in <12h prio: urgent Needs to be resolved now(?) and removed prio: high Needs to be resolved ASAP. labels Oct 12, 2022
@timobrembeck timobrembeck changed the title Editing LinkObjects results in violation of unique_versions Replacing links used in multiple pages causes internal server error Oct 12, 2022
@timobrembeck
Copy link
Member

The error is caused by these lines:

translations = {link.content_object for link in old_url.region_links}
# Replace the old urls with the new urls in the content
for translation in translations:
new_translation = deepcopy(translation)
# Replace link in translation
logger.debug("Replacing links of %r", new_translation)
new_translation.content = rewrite_links(
new_translation.content,
partial(self.replace_link, old_url.url, new_url),
)
# Save translation with replaced content as new minor version
new_translation.id = None
new_translation.version += 1

But only in the condition that the database is already broken - if links exist to old translation versions. So this is somehow a follow-up error of some other known (#1513, #1604) or unknown bug and not a problem on itself...

@timobrembeck timobrembeck closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2022
@timobrembeck timobrembeck added wontfix This will not be worked on and removed bug Something isn't working effort: medium Should be doable in <12h prio: urgent Needs to be resolved now(?) labels Nov 1, 2022
@timobrembeck timobrembeck removed this from the 22Q4 milestone Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants