Skip to content

Fix sharing issues where owner project has been previously migrated but not in current migration run - #203

Open
ruaridhg wants to merge 9 commits into
mainfrom
rmg/fix-sharing-issues
Open

Fix sharing issues where owner project has been previously migrated but not in current migration run#203
ruaridhg wants to merge 9 commits into
mainfrom
rmg/fix-sharing-issues

Conversation

@ruaridhg

@ruaridhg ruaridhg commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This PR:

  • migration.py handles the likely case where the owner project has been migrated in a previous migration run and the project in the current run has resources shared into it. Previously, the sharing would only work if both the owner project and shared into project were migrated in the same migration run.
  • Handle shared subject reruns where the owner project already exists on the destination but is not present in the current migration ID map
  • Fix tests/unit/test_users.py by moving into tests/integration/test_users.py since the test uses the actual xnat4test source and destination

@ruaridhg ruaridhg changed the title Rmg/fix sharing issues Fix sharing issues where owner project has been previously migrated but not in current migration run Jun 26, 2026
@ruaridhg
ruaridhg marked this pull request as ready for review June 26, 2026 14:54
@ruaridhg
ruaridhg requested a review from p-j-smith June 26, 2026 15:36
@ruaridhg ruaridhg closed this Jun 30, 2026
@ruaridhg ruaridhg reopened this Jul 24, 2026

@p-j-smith p-j-smith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering whether this is an issue you ran into? There are a few parts I'm not sure about (e.g. is setting root.attrib["project"] correct).

I think it might be simpler if we only support migrating all related projects at the same time. Do you know if there's an easy way to check / enforce this?

Comment thread src/xmigrate/migration.py
Comment on lines 775 to +779
sharing_info = self.assessor_sharing.get(assessor.id, {"owner": None, "projects": []})
if root.attrib["project"] != self.source_info.id:
# this project is not the owner of the resource, no need to create it on the destination
sharing_info["projects"].append(self.destination_info.id)
owner_project = root.attrib["project"]
sharing_info["owner"] = owner_project

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment says 'this project is not the owner of the resource' (i.e. root.attrib["project"] is not the owner), but on line 778 root.attrib["project"] is then set as the owner_project

Comment thread src/xmigrate/migration.py
Comment on lines -792 to +815
if (
assessor.label
not in self.destination_connection.projects[self.destination_info.id]

destination_experiment = (
self.destination_connection.projects[self.destination_info.id]
.subjects[subject.label]
.experiments[experiment.label]
.assessors
):
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering why the check is changing. Does the current check miss some assessors?

I think the first check gets all assessors for the project, and the second only gets the assessors for the experiment. Do you know which is correct?

Comment thread src/xmigrate/migration.py
Comment on lines -928 to +961
# Skip resource creation for this subject if it is shared and this project is not the owner
sharing_info = self.subject_sharing[subject.label]
if sharing_info["owner"] != self.destination_info.id:
continue
subject_sharing_info = self.subject_sharing[subject.label]
subject_is_shared = subject_sharing_info["owner"] != self.destination_info.id

for experiment in subject.experiments:
self._create_experiment(experiment, destination_datatypes)
if subject_is_shared:
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the subject is shared, then do we still want to create the experiment? I think we're assuming that if a subject is shared, all resources within that subject should belong to the subject project, not the one it's shared into

Comment thread src/xmigrate/migration.py
Comment on lines +1105 to +1108
if (
owner not in self.destination_connection.projects
or label not in self.destination_connection.projects[owner].subjects
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the info not always exist in the mapper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants