wger icon indicating copy to clipboard operation
wger copied to clipboard

Template Routine cant be copied back to own Routine

Open EtheriousNight opened this issue 6 months ago • 0 comments

Priority/Impact

High (critical issue, blocks workflow)

Description

Hello, I encountered the bug where I can't copy a template back to my own routine...

I recreated the bug on the Test-Instance (wger-master.rge.uber.space) with the following steps:

  1. Create workout with 2 exercises with custom min and max Rest time
  2. Manage Template -> own + public template
  3. try to copy it back to ur own routines

I locked into the DB and it seems like the backend does not increment the slot entry_id for the second exercise. Should be an easy fix and I would do it myself, but i cant get the code running on my machine with no additional tinkering.... Would be nice to get some commands or steps to setup the repository ^^

For anyone that runs into the same issue, try these steps with some Database tinkering (DO AT YOUR OWN RISK or wait for an update which fixes this error):

  1. Search for your routine in the "manager_routine" table and note the id down.
  2. Table "manager_day" search for your routine_id and note the id for the first day.
  3. Table "manager_slotentry" search for your slot_id and note the all id's for the first day.
  4. Table "manager_maxrestconfig" delete all rows with the same slot_entry_id's.
  5. do the same with the other days in your workout

If you have any questions feel free to ask ^^

Logs

db-1 | 2025-06-01 08:27:12.667 UTC [861200] ERROR: duplicate key value violates unique constraint "manager_maxrestconfig_slot_entry_id_iteration_aba141a0_uniq" db-1 | 2025-06-01 08:27:12.667 UTC [861200] DETAIL: Key (slot_entry_id, iteration)=(198, 1) already exists. db-1 | 2025-06-01 08:27:12.667 UTC [861200] STATEMENT: INSERT INTO "manager_maxrestconfig" ("slot_entry_id", "iteration", "operation", "step", "repeat", "requirements", "value") VALUES (198, 1, 'r', 'na', false, NULL, 90) RETURNING "manager_maxrestconfig"."id" web-1 | level=ERROR ts=2025-06-01 10:27:12,669 module=log path=/home/wger/.local/lib/python3.12/site-packages/django/utils/log.py line=248 message=Internal Server Error: /de/routine/9/copy web-1 | Traceback (most recent call last): web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute web-1 | return self.cursor.execute(sql, params) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute web-1 | raise ex.with_traceback(None) web-1 | psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "manager_maxrestconfig_slot_entry_id_iteration_aba141a0_uniq" web-1 | DETAIL: Key (slot_entry_id, iteration)=(198, 1) already exists. web-1 | web-1 | The above exception was the direct cause of the following exception: web-1 | web-1 | Traceback (most recent call last): web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner web-1 | response = get_response(request) web-1 | ^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response web-1 | response = wrapped_callback(request, *callback_args, **callback_kwargs) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/contrib/auth/decorators.py", line 59, in _view_wrapper web-1 | return view_func(request, *args, **kwargs) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/src/wger/manager/views/routine.py", line 104, in copy_routine web-1 | copy_config(current_entry.maxrestconfig_set.all(), slot_entry_copy) web-1 | File "/home/wger/src/wger/manager/views/routine.py", line 60, in copy_config web-1 | config_copy.save() web-1 | File "/home/wger/src/wger/manager/models/abstract_config.py", line 136, in save web-1 | super().save(**kwargs) web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/base.py", line 902, in save web-1 | self.save_base( web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/base.py", line 1008, in save_base web-1 | updated = self._save_table( web-1 | ^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/base.py", line 1169, in _save_table web-1 | results = self._do_insert( web-1 | ^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/base.py", line 1210, in _do_insert web-1 | return manager._insert( web-1 | ^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method web-1 | return getattr(self.get_queryset(), name)(*args, **kwargs) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/query.py", line 1864, in _insert web-1 | return query.get_compiler(using=using).execute_sql(returning_fields) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql web-1 | cursor.execute(sql, params) web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute web-1 | return self._execute_with_wrappers( web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers web-1 | return executor(sql, params, many, context) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute web-1 | with self.db.wrap_database_errors: web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/utils.py", line 91, in exit web-1 | raise dj_exc_value.with_traceback(traceback) from exc_value web-1 | File "/home/wger/.local/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute web-1 | return self.cursor.execute(sql, params) web-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ web-1 | File "/home/wger/.local/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute web-1 | raise ex.with_traceback(None) web-1 | django.db.utils.IntegrityError: duplicate key value violates unique constraint "manager_maxrestconfig_slot_entry_id_iteration_aba141a0_uniq" web-1 | DETAIL: Key (slot_entry_id, iteration)=(198, 1) already exists.

Server version

No response

Mobile app version

No response

EtheriousNight avatar Jun 01 '25 08:06 EtheriousNight