Bug 53788 - Migrate from djcelery to django_celery_results during upgrade from UCS 4.4 to UCS 5.0
Migrate from djcelery to django_celery_results during upgrade from UCS 4.4 to...
Status: CLOSED INVALID
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 5.0
Other Linux
: P5 normal (vote)
: UCS@school 4.4 v9-errata
Assigned To: Florian Best
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-09-14 12:58 CEST by Florian Best
Modified: 2021-10-19 12:07 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2021-09-14 12:58:59 CEST
The currently used djcelery is only available for Python 2. For Python 3 there is the Python 2 compatible django_celery_results.

A django database schema migration is only possible with both versions installed, so we need to do this with Python 2 in UCS 4.4.

So we have to migrate the database schema in a preup.sh of UCS@school 5.0 component.
Therefore we need to backport python-django-celery-results from debian buster into ucs-school-4.4 and adjust the package so that it ships Python 2 packages instead of Python 3 packages. And release it as errata update for UCS@school 4.4.
Comment 1 Florian Best univentionstaff 2021-09-14 13:00:45 CEST
According to https://pypi.org/project/django-celery-results/1.0.4/ the version 1.0.4 from debian buster is Python 2 compatible.
Comment 2 Florian Best univentionstaff 2021-09-14 22:27:17 CEST
This way does not work because:
djcelery depends on python-celery < 3
django_celery_results depends on python-celery >= 4

I could find a workaround by:
pip install celery==4.1.0
mv /usr/local/lib/python2.7/dist-packages/celery{,4} /usr/local/lib/python2.7/dist-packages/kombu{,2}
sed -i 's/from celery/from celery4/g; s/import celery/import celery4/g; s/from kombu/from kombu2/g; s/import kombu/import kombu2/g' $(find /usr/lib/python2.7/dist-packages/django_celery_results /usr/local/lib/python2.7/ -name '*.py')

python -m ucsschool.http_api.manage squashmigrations import_api 0001_initial 0003
python -m ucsschool.http_api.manage sqlmigrate import_api 0004
→ gives us some SQL statements:

ALTER TABLE "import_api_userimportjob" DROP CONSTRAINT "impor_result_id_7383b884_fk_django_celery_results_taskresult_id";                                                                                                                     
ALTER TABLE "import_api_userimportjob" ADD CONSTRAINT "impor_result_id_7383b884_fk_django_celery_results_taskresult_id" FOREIGN KEY ("result_id") REFERENCES "django_celery_results_taskresult" ("id") DEFERRABLE INITIALLY DEFERRED;         
COMMIT;

They are wrong, but can be used as a basis.

The migrations have been squashed and the joinscript has been increased/adjusted to include the upgrade manually:

    su - postgres -c "psql -d '$POSTGRES_DB' -c \"delete from django_migrations where app='import_api';\"" || die 'Failed removing django migrations'
    python3 -m ucsschool.http_api.manage migrate --no-color --noinput django_celery_results || die 'Failed initializing django_celery_results'
    su - postgres -c "psql -d '$POSTGRES_DB' -c 'ALTER TABLE "import_api_userimportjob" DROP CONSTRAINT "import_api_userimportj_result_id_7383b884_fk_celery_taskmeta_id";'" || die 'Failed to drop djcelery constraint'
    su - postgres -c "psql -d '$POSTGRES_DB' -c 'ALTER TABLE "import_api_userimportjob" ADD CONSTRAINT "impor_result_id_7383b884_fk_django_celery_results_taskresult_id" FOREIGN KEY ("result_id") REFERENCES "django_celery_results_taskresult" ("id") DEFERRABLE INITIALLY DEFERRED;'" || die 'Failed to create django_celery_results constraint'
    python3 -m ucsschool.http_api.manage migrate --no-color --noinput --fake-initial import_api

ucs-school-import (18.0.2)
877ad756a407 | fixup! fixup! Bug #53451: replace djcelery with django-celery-results
Comment 3 Ole Schwiegert univentionstaff 2021-10-19 12:07:47 CEST
Lost Bugs round before the school release: Since this is marked as invalid by the author and the solution was implemented with Bug #53451 we close the bug. If this error should occur again, please clone or reopen the Bug.