Skip to content

Commit

Permalink
Fix copy_project
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 29, 2024
1 parent 9e07a4e commit e2ad5d2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion rdmo/projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf import settings
from django.contrib.sites.models import Site
from django.db import connection
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.timezone import now
Expand Down Expand Up @@ -110,7 +111,23 @@ def copy_project(project, site, owners):
Value.objects.bulk_create(project_snapshot_values)

for value, file_name, file_content in file_values:
value.copy_file(file_name, file_content)
if connection.vendor == 'postgres':
# bulk_create will only set the primary key on cool databases
# https://docs.djangoproject.com/en/4.2/ref/models/querysets/#bulk-create
value.copy_file(file_name, file_content)
else:
# refetch the value from the database, we use filter and first here to be more
# stable against weird cases, where collection_index is not unique
db_value = Value.objects.filter(
project=value.project,
snapshot=value.snapshot,
attribute=value.attribute,
set_prefix=value.set_prefix,
set_index=value.set_index,
collection_index=value.collection_index
).first()
if db_value and db_value.file_name == file_name:
db_value.copy_file(file_name, file_content)

for owner in owners:
membership = Membership(project=project, user=owner, role='owner')
Expand Down

0 comments on commit e2ad5d2

Please sign in to comment.