anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: rdmorganiser/rdmo
Issue: Nested projects: cancel button actually imports data

### Description / Beschreibung

In nested projects if someone opens the import from parent project and then decides not to import anything by clicking <kbd>Cancel</kbd> the data will be imported anyway.

### Expected behaviour / Erwartetes Verhalten

Expected behaviour is to get back to the project details view without any changes to the answers, i.e. not importing anything from the parent project.

### Steps to reproduce / Schritte zum Reproduzieren

1. Create a project and add some answers
2. Create a child project
3. In the child project go the import from parent project view
4. Click <kbd>Cancel</kbd> button
5. Answers are imported to the child project.



Changed files:
rdmo/projects/mixins.py

diff --git a/rdmo/projects/mixins.py b/rdmo/projects/mixins.py
index 1cec2750..c506de83 100644
--- a/rdmo/projects/mixins.py
+++ b/rdmo/projects/mixins.py
@@ -204,6 +204,12 @@ class ProjectImportMixin(object):
     def import_project(self):
         current_project = self.object
 
+        if 'cancel' in self.request.POST:
+            if current_project:
+                return HttpResponseRedirect(current_project.get_absolute_url())
+            else:
+                return HttpResponseRedirect(self.success_url)
+
         # get the original project
         project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))
Repository: rdmorganiser/rdmo
Issue: Users with same email can not be invited

### Description / Beschreibung

Surprisingly, email addresses in RDMO don't have to be unique. I you invite an existin user to a project via email with a non unique mail the managers `.get()` function raises a `MultipleObjectsReturned`.

### Expected behaviour / Erwartetes Verhalten

(a) emails should unique in the first place or
(b) both users should be invited

Probably (b) is easier to implement.

Changed files:
rdmo/projects/forms.py

diff --git a/rdmo/projects/forms.py b/rdmo/projects/forms.py
index ba9b85f9..9bf14d24 100644
--- a/rdmo/projects/forms.py
+++ b/rdmo/projects/forms.py
@@ -192,16 +192,17 @@ class MembershipCreateForm(forms.Form):
 
     def clean_username_or_email(self):
         username_or_email = self.cleaned_data['username_or_email']
+        usermodel = get_user_model()
 
-        # check if it is a registered
+        # check if it is a registered user
         try:
-            self.cleaned_data['user'] = get_user_model().objects.get(Q(username=username_or_email) | Q(email__iexact=username_or_email))
+            self.cleaned_data['user'] = usermodel.objects.get(Q(username=username_or_email) | Q(email__iexact=username_or_email))
             self.cleaned_data['email'] = self.cleaned_data['user'].email
 
             if self.cleaned_data['user'] in self.project.user.all():
                 raise ValidationError(_('The user is already a member of the project.'))
 
-        except get_user_model().DoesNotExist:
+        except (usermodel.DoesNotExist, usermodel.MultipleObjectsReturned):
             if settings.PROJECT_SEND_INVITE:
                 # check if it is a valid email address, this will raise the correct ValidationError
                 EmailValidator()(username_or_email)
Repository: rdmorganiser/rdmo
Issue: Sorting causes problems with import

### Description / Beschreibung

When using different `uri_prefix`es for, e.g. a domain import, the sorting by `uri` destroys the order in the file, and parent Attributes are imported *after* their children (with a different `uri_prefix` earlier in the alphabet). This is the problematic line:

https://github.com/rdmorganiser/rdmo/blob/master/rdmo/core/xml.py#L52

### Expected behaviour / Erwartetes Verhalten

I am not sure if we could get rid of the sorting, we could also sort by `path` (which would give the field some meaning in the xml again). Ideas? @triole @MyPyDavid 


Changed files:
rdmo/core/constants.py, rdmo/core/xml.py

diff --git a/rdmo/core/constants.py b/rdmo/core/constants.py
index f5be7b34..9a8d6a4f 100644
--- a/rdmo/core/constants.py
+++ b/rdmo/core/constants.py
@@ -55,3 +55,12 @@ PERMISSIONS = {
         'views.add_view', 'views.change_view', 'views.delete_view'
     )
 }
+
+IMPORT_SORT_ORDER = (
+    'domain',
+    'conditions',
+    'options',
+    'questions',
+    'tasks',
+    'views'
+)
diff --git a/rdmo/core/xml.py b/rdmo/core/xml.py
index 79612024..7f517c1d 100644
--- a/rdmo/core/xml.py
+++ b/rdmo/core/xml.py
@@ -3,6 +3,9 @@ import re
 
 import defusedxml.ElementTree as ET
 
+from .constants import IMPORT_SORT_ORDER
+
+
 log = logging.getLogger(__name__)
 
 
@@ -49,7 +52,7 @@ def flat_xml_to_elements(treenode):
 
         elements.append(element)
 
-    elements = sort_elements_by_key(elements, 'uri')
+    elements = sorted(elements, key=sort_elements)
     return elements
 
 
@@ -92,5 +95,13 @@ def filter_elements_by_type(elements, element_type):
             yield element
 
 
-def sort_elements_by_key(dictlist, key, reverse=False):
-    return sorted(dictlist, key=lambda k: k[key], reverse=reverse)
+def sort_elements(element):
+    # remove the uri_prefix from the uri to create the key to be sorted by
+    sort_key = element['uri'].replace(element['uri_prefix'], '')
+
+    # remove the app name from the sort_key and replace it by its import order
+    for i, item in enumerate(IMPORT_SORT_ORDER):
+        if sort_key.startswith(item):
+            sort_key = sort_key.replace(item, str(i))
+
+    return sort_key
Repository: nipreps/niworkflows
Issue: Melodic report ignores TR units

https://github.com/poldracklab/niworkflows/blob/7594df0f4a7bb054e51e2d1f31586017c3cade81/niworkflows/viz/utils.py#L505

Those can be seconds or msec. There is a field for it in the nifti header.

Changed files:
niworkflows/viz/utils.py

diff --git a/niworkflows/viz/utils.py b/niworkflows/viz/utils.py
index e73bd8d0..be6c9b82 100644
--- a/niworkflows/viz/utils.py
+++ b/niworkflows/viz/utils.py
@@ -503,6 +503,18 @@ def plot_melodic_components(melodic_dir, in_file, tr=None,
     in_nii = nb.load(in_file)
     if not tr:
         tr = in_nii.header.get_zooms()[3]
+        units = in_nii.header.get_xyzt_units()
+        if units:
+            if units[-1] == 'msec':
+                tr = tr / 1000.0
+            elif units[-1] == 'usec':
+                tr = tr / 1000000.0
+            elif units[-1] != 'sec':
+                NIWORKFLOWS_LOG.warn('Unknown repetition time units '
+                                     'specified - assuming seconds')
+        else:
+            NIWORKFLOWS_LOG.warn(
+                'Repetition time units not specified - assuming seconds')
 
     from nilearn.input_data import NiftiMasker
     from nilearn.plotting import plot_roi
Repository: nipreps/niworkflows
Issue: Fatal Python error: Bus error

As reported by @marcelzwiers in poldracklab/mriqc#717 and diagnosed by @effigies (https://github.com/poldracklab/mriqc/issues/717#issuecomment-395526216), there is a problem in `niworkflows/interfaces/utils.py`, line 179 (`_copyxform`) when using nibabel with mmap.

Changed files:
niworkflows/interfaces/utils.py

diff --git a/niworkflows/interfaces/utils.py b/niworkflows/interfaces/utils.py
index 3a69be14..1c0afbc2 100644
--- a/niworkflows/interfaces/utils.py
+++ b/niworkflows/interfaces/utils.py
@@ -157,7 +157,8 @@ class GenerateSamplingReference(SimpleInterface):
 
 def _copyxform(ref_image, out_image, message=None):
     # Read in reference and output
-    resampled = nb.load(out_image)
+    # Use mmap=False because we will be overwriting the output image
+    resampled = nb.load(out_image, mmap=False)
     orig = nb.load(ref_image)
 
     if not np.allclose(orig.affine, resampled.affine):
Repository: nipreps/niworkflows
Issue: Update atime when copying FreeSurfer

`shutil.copytree` uses `shutil.copy2`, which uses `shutil.copystat`. When we copy FreeSurfer `fsaverage*` directories, we are creating outputs that look as if they have not been accessed (atime) or modified (mtime) since whatever those are in the bundled FreeSurfer subjects. These may be what they are in the FreeSurfer distribution bundle.

The upshot is that on filesystems that do age-based sweeping (e.g. `/scratch` directories on many HPC clusters), we are basically setting users up to have critical files removed from under them.

This should hit fMRIPrep 20.2.x, 21.0.x and 22.0.x.

Changed files:
niworkflows/interfaces/bids.py

diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py
index b37318e8..ff31ae6d 100644
--- a/niworkflows/interfaces/bids.py
+++ b/niworkflows/interfaces/bids.py
@@ -4,7 +4,7 @@
 from collections import defaultdict
 from json import dumps, loads
 from pathlib import Path
-from shutil import copytree, rmtree
+import shutil
 from pkg_resources import resource_filename as _pkgres
 import re
 
@@ -869,10 +869,15 @@ class BIDSFreeSurferDir(SimpleInterface):
 
             # Finesse is overrated. Either leave it alone or completely clobber it.
             if dest.exists() and self.inputs.overwrite_fsaverage:
-                rmtree(dest)
+                shutil.rmtree(dest)
             if not dest.exists():
                 try:
-                    copytree(source, dest)
+                    # Use copy instead of copy2; copy calls copymode while copy2 calls
+                    # copystat, which will preserve atime/mtime.
+                    # atime should *not* be copied to avoid triggering processes that
+                    # sweep un-accessed files.
+                    # If we want to preserve mtime, that will require a new copy function.
+                    shutil.copytree(source, dest, copy_function=shutil.copy)
                 except FileExistsError:
                     LOGGER.warning(
                         "%s exists; if multiple jobs are running in parallel"