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

Manual Fix #437

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Manual Fix #437

wants to merge 1 commit into from

Conversation

goast-ai[bot]
Copy link

@goast-ai goast-ai bot commented Sep 18, 2024

Link to Goast Fix

  1. /djAerolith/wordwalls/game.py Modify the get_or_create_dc method to use Django's get_or_create method to handle the race condition atomically. Add a retry mechanism to handle potential IntegrityError by retrying the operation.

Stack Trace

File "/opt/webolith/djAerolith/wordwalls/game.py", line 269, in get_or_create_dc
qs, secs, dc = self.get_dc(ch_date, ch_lex, ch_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/game.py", line 192, in get_dc
dc = DailyChallenge.objects.get(date=ch_date, lexicon=ch_lex, name=ch_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
wordwalls.models.DailyChallenge.DoesNotExist: DailyChallenge matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 165, in execute
return self._trace_method(
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/psycopg/cursor.py", line 14, in _trace_method
return super(Psycopg3TracedCursor, self)._trace_method(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 132, in _trace_method
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "wordwalls_dailychallenge_name_id_20e8e28a4fd6b6e3_uniq"
DETAIL:  Key (name_id, lexicon_id, date)=(17, 18, 2021-06-05) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/webolith/djAerolith/wordwalls/game.py", line 291, in get_or_create_dc
dc.save()
File "/app/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 814, in save
self.save_base(
File "/app/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 877, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1020, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1061, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1805, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
cursor.execute(sql, params)
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 165, in execute
return self._trace_method(
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/psycopg/cursor.py", line 14, in _trace_method
return super(Psycopg3TracedCursor, self)._trace_method(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 132, in _trace_method
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/app/.venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 165, in execute
return self._trace_method(
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/psycopg/cursor.py", line 14, in _trace_method
return super(Psycopg3TracedCursor, self)._trace_method(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 132, in _trace_method
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: duplicate key value violates unique constraint "wordwalls_dailychallenge_name_id_20e8e28a4fd6b6e3_uniq"
DETAIL:  Key (name_id, lexicon_id, date)=(17, 18, 2021-06-05) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/trace_utils.py", line 335, in wrapper
return func(mod, pin, wrapped, instance, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/django/patch.py", line 326, in wrapped
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapper_view
return view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/views/decorators/http.py", line 43, in inner
return func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/api.py", line 226, in wrap
return f(request, parsed_req, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/api.py", line 270, in new_challenge
tablenum = WordwallsGame().initialize_daily_challenge(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/game.py", line 223, in initialize_daily_challenge
ret = self.get_or_create_dc(ch_date, ch_lex, ch_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/game.py", line 296, in get_or_create_dc
qs, secs, dc = self.get_dc(ch_date, ch_lex, ch_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/webolith/djAerolith/wordwalls/game.py", line 192, in get_dc
dc = DailyChallenge.objects.get(date=ch_date, lexicon=ch_lex, name=ch_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 633, in get
num = len(clone)
^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 380, in __len__
self._fetch_all()
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 91, in __iter__
results = compiler.execute_sql(
^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
cursor.execute(sql, params)
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 165, in execute
return self._trace_method(
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/psycopg/cursor.py", line 14, in _trace_method
return super(Psycopg3TracedCursor, self)._trace_method(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/ddtrace/contrib/dbapi/__init__.py", line 132, in _trace_method
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 83, in _execute
self.db.validate_no_broken_transaction()
File "/app/.venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 531, in validate_no_broken_transaction
raise TransactionManagementError(
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

Copy link
Author

goast-ai bot commented Sep 18, 2024

NEW FEATURES

  • Request changes to the PR by tagging @goast-ai in a comment and telling it what you want it to change. Goast will update the PR using the additional information in your comment.
  • Was this PR not needed or wrong? Help Goast learn what to ignore or do differently next time by commenting why when closing the PR.

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 this pull request may close these issues.

0 participants