Browse Source

ref: add deletion protection to sentry_activity pickle migration (#52287)

to fix:

```
  File "/usr/src/sentry/src/sentry/migrations/0493_pickle_to_json_sentry_activity.py", line 14, in _backfill
    obj.save(update_fields=["data"])
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 743, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 780, in save_base
    updated = self._save_table(
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 858, in _save_table
    raise DatabaseError("Save with update_fields did not affect any rows.")
django.db.utils.DatabaseError: Save with update_fields did not affect any rows.
```

similar to what is done in migration 492
anthony sottile 1 year ago
parent
commit
98ac53647a
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/sentry/migrations/0493_pickle_to_json_sentry_activity.py

+ 6 - 1
src/sentry/migrations/0493_pickle_to_json_sentry_activity.py

@@ -1,6 +1,8 @@
 # Generated by Django 2.2.28 on 2023-05-19 17:25
+import logging
 
 from django.db import migrations
+from django.db.utils import DatabaseError
 
 from sentry.new_migrations.migrations import CheckedMigration
 from sentry.utils.query import RangeQuerySetWrapperWithProgressBarApprox
@@ -11,7 +13,10 @@ def _backfill(apps, schema_editor):
 
     for obj in RangeQuerySetWrapperWithProgressBarApprox(cls.objects.all()):
         # load pickle, save json
-        obj.save(update_fields=["data"])
+        try:
+            obj.save(update_fields=["data"])
+        except DatabaseError as e:
+            logging.warning(f"ignoring save error (row was likely deleted): {e}")
 
 
 class Migration(CheckedMigration):