Fix ImproperlyConfigured for scrobble-detail by backfilling NULL UUIDs

The ScrobbleSerializer uses HyperlinkedModelSerializer with
lookup_field='uuid', but 3,273 of 6,155 Scrobbles had NULL UUIDs,
causing URL resolution to fail.

Fix:
- Add migration 0104 to backfill NULL UUIDs with uuid4()
- All Scrobbles now have valid UUIDs for URL resolution
This commit is contained in:
2026-07-23 20:37:52 -04:00
parent dcbb4034d0
commit 7e222c9a8a

View File

@ -0,0 +1,25 @@
from django.db import migrations
def backfill_uuids(apps, schema_editor):
Scrobble = apps.get_model("scrobbles", "Scrobble")
from uuid import uuid4
scrobbles = Scrobble.objects.filter(uuid__isnull=True)
# Process in batches to avoid loading all into memory
while scrobbles.exists():
batch = list(scrobbles[:1000])
for s in batch:
s.uuid = uuid4()
Scrobble.objects.bulk_update(batch, ["uuid"], batch_size=1000)
class Migration(migrations.Migration):
dependencies = [
("scrobbles", "0103_scrobble_species_observation_and_more"),
]
operations = [
migrations.RunPython(backfill_uuids, migrations.RunPython.noop),
]