wger
wger copied to clipboard
Languages sync patch via command (docker issues #78)
Proposed Changes
- I added a command to core management
sync_core_languageswhich fixes the error of languages having different IDs if we deleted some and made an exercise sync after (https://github.com/wger-project/docker/issues/78) - Temporal patch while https://github.com/wger-project/wger/issues/1667 gets developped
Please check that the PR fulfills these requirements
- [X] Tests for the changes have been added (for bug fixes / features)
- [X] Added yourself to AUTHORS.rst
Other questions
If you encounter the languages problem (e.g. https://github.com/wger-project/docker/issues/78), just run:
manage.py sync_core_languagesordocker compose exec web python3 manage.py sync_core_languages
I didn't manage to get the test running locally if someone can help.
The command itself works as expected:
We delete language 22 (Croatian) and sync exercises, so it creates it with last id +1 (45 here)
The sync fails:
After running this new command sync_core_languages:
Croatian gets back to 22 and the sync is performed without problems
Tests weren't passing because it was Postgre specific. Now they do work (https://github.com/Victorivus/wger/pull/1/checks).
Changes made:
- Removed PostgreSQL-specific commands: Removed
SET session_replication_role = 'replica';andSET session_replication_role = 'origin';. - Temporary table creation: Used
CREATE TEMPORARY TABLEand handled the case if it's not supported by falling back toCREATE TEMP TABLE. - Django ORM: Used Django ORM for updating or creating records in the
core_languagetable. - Database compatibility: Made sure the SQL used for inserting and updating records is compatible with both PostgreSQL and SQLite.
Test in "production" was done as so:
- Run
docker exec -ti wger_db psql -U wger - #
DELETE FROM exercises_exercise WHERE language_id =22; DELETE from core_language where id=22; - The command
sync-exercises(docker compose exec web python3 manage.py sync-exercises) will now throw errors and not work, it will create languages wth different ids than original ones. - Run this PR's command
sync_core_languages(docker compose exec web python3 manage.py sync_core_languages) - Now
sync-exercises(docker compose exec web python3 manage.py sync-exercises) will work properly as expected.
@rolandgeider just to let you know that I fixed the test pipeline if you want to rerun it
haven't forgotten you, will take a look this weekend