Skip to content

Commit 9f66cb9

Browse files
jirivranyCopilot
andauthored
Update scripts/migrate_v0x_to_v1.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f42c480 commit 9f66cb9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

scripts/migrate_v0x_to_v1.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ def migrate_org_data():
6767

6868
updated = 0
6969
for row in data_records:
70-
orgs = row.user.organization.all()
70+
user = getattr(row, "user", None)
71+
if user is None:
72+
# Skip records that have no associated user to avoid AttributeError
73+
# and leave them for potential manual investigation.
74+
print(f" {model_name}: skipping record id={getattr(row, 'id', 'unknown')} with no associated user")
75+
continue
76+
orgs = user.organization.all()
7177
if len(orgs) == 1:
7278
row.org_id = orgs[0].id
7379
updated += 1
7480
else:
75-
users_with_multiple_orgs[row.user.email] = [org.name for org in orgs]
81+
users_with_multiple_orgs[user.email] = [org.name for org in orgs]
7682

7783
try:
7884
db.session.commit()

0 commit comments

Comments
 (0)