diff --git a/api/funkwhale_api/common/scripts/migrate_to_user_libraries.py b/api/funkwhale_api/common/scripts/migrate_to_user_libraries.py index 54ba5d503..537794b62 100644 --- a/api/funkwhale_api/common/scripts/migrate_to_user_libraries.py +++ b/api/funkwhale_api/common/scripts/migrate_to_user_libraries.py @@ -71,7 +71,15 @@ def update_uploads(libraries_by_user, stdout): def update_orphan_uploads(open_api, stdout): privacy_level = "everyone" if open_api else "instance" - first_superuser = User.objects.filter(is_superuser=True).order_by("pk").first() + first_superuser = ( + User.objects.filter(is_superuser=True) + .exclude(actor=None) + .order_by("pk") + .first() + ) + if not first_superuser: + stdout.write("* No superuser found, skipping update orphan uploads") + return library, _ = models.Library.objects.get_or_create( name="default", actor=first_superuser.actor, diff --git a/api/funkwhale_api/users/models.py b/api/funkwhale_api/users/models.py index 197ef0dc8..2bc87588e 100644 --- a/api/funkwhale_api/users/models.py +++ b/api/funkwhale_api/users/models.py @@ -285,7 +285,7 @@ def create_actor(user): args["private_key"] = private.decode("utf-8") args["public_key"] = public.decode("utf-8") - return federation_models.Actor.objects.create(**args) + return federation_models.Actor.objects.create(user=user, **args) @receiver(ldap_populate_user) diff --git a/docs/upgrading/0.17.rst b/docs/upgrading/0.17.rst index 4a7093b1f..1414b563e 100644 --- a/docs/upgrading/0.17.rst +++ b/docs/upgrading/0.17.rst @@ -189,10 +189,14 @@ then run the migrations script. On docker-setups:: + # if you missed this one from a previous upgrade + docker-compose run --rm api python manage.py script create_actors --no-input docker-compose run --rm api python manage.py script migrate_to_user_libraries --no-input On non docker-setups:: + # if you missed this one from a previous upgrade + python api/manage.py script create_actors --no-input python api/manage.py script migrate_to_user_libraries --no-input If the scripts ends without errors, you're instance should be updated and ready to use :)