internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: akvo/akvo-rsr

Issue:
Split web service for local environment
Currently, the `web` docker-compose service uses [`start-django.sh`](https://github.com/akvo/akvo-rsr/blob/master/scripts/docker/dev/start-django.sh) which starts 3 different processes in the background. This introduces these problems:

 - restarting other processes when only one is needed
 - throwing away logs (the `web` service only outputs stuff before the background processes are started)
 - inability to debug the processes (can't attach remote debugger nor read logs)


Discussion:

Resolving patch:
diff --git a/manage.py b/manage.py
old mode 100644
new mode 100755


Test patch:
Repository: akvo/akvo-rsr

Issue:
Cache project directory response



Discussion:

Resolving patch:
diff --git a/akvo/rest/cache.py b/akvo/rest/cache.py
--- a/akvo/rest/cache.py
+++ b/akvo/rest/cache.py
@@ -1,12 +1,10 @@
 #!/usr/bin/env python3
 
-from django.core.cache import caches
 from akvo.cache import cache_with_key, delete_cache_data
 from akvo.rest.serializers import ProjectDirectorySerializer
 from akvo.rsr.models.project import Project, project_directory_cache_key
 
 PROJECT_DIRECTORY_CACHE = 'database'
-PROJECT_DIRECTORY_ALL_KEY = 'project_directory_all'
 
 
 # NOTE: The data doesn't timeout, since we expect the data to be invalidated
@@ -38,4 +36,3 @@ def serialized_project(project_id):
 
 def delete_project_from_project_directory_cache(project_id):
     delete_cache_data(project_directory_cache_key(project_id), PROJECT_DIRECTORY_CACHE)
-    caches[PROJECT_DIRECTORY_CACHE].delete(PROJECT_DIRECTORY_ALL_KEY)
diff --git a/akvo/rest/views/project.py b/akvo/rest/views/project.py
--- a/akvo/rest/views/project.py
+++ b/akvo/rest/views/project.py
@@ -5,9 +5,9 @@
 For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
 """
 
-from django.core.cache import caches
 from django.db.models import Q
 from django.shortcuts import get_object_or_404
+from django.views.decorators.cache import cache_page
 from rest_framework.authentication import SessionAuthentication
 from rest_framework.decorators import api_view, authentication_classes, permission_classes
 from rest_framework.permissions import IsAuthenticated
@@ -16,7 +16,7 @@
 from geojson import Feature, Point, FeatureCollection
 
 from akvo.codelists.store.default_codelists import SECTOR_CATEGORY
-from akvo.rest.cache import serialized_project, PROJECT_DIRECTORY_CACHE, PROJECT_DIRECTORY_ALL_KEY
+from akvo.rest.cache import serialized_project
 from akvo.rest.serializers import (ProjectSerializer, ProjectExtraSerializer,
                                    ProjectExtraDeepSerializer,
                                    ProjectIatiExportSerializer,
@@ -267,6 +267,7 @@ class ProjectUpViewSet(ProjectViewSet):
 ###############################################################################
 
 @api_view(['GET'])
+@cache_page(60 * 60)
 def project_directory(request):
     """Return the values for various project filters.
 
@@ -277,13 +278,9 @@ def project_directory(request):
 
     page = request.rsr_page
     projects = _project_list(request)
-    cache = caches[PROJECT_DIRECTORY_CACHE]
-    projects_data = None if page else cache.get(PROJECT_DIRECTORY_ALL_KEY)
-    if projects_data is None:
-        projects_data = [
-            serialized_project(project_id) for project_id in projects.values_list('pk', flat=True)
-        ]
-        cache.set(PROJECT_DIRECTORY_ALL_KEY, projects_data)
+    projects_data = [
+        serialized_project(project_id) for project_id in projects.values_list('pk', flat=True)
+    ]
     organisations = list(projects.all_partners().values('id', 'name', 'long_name'))
     organisations = TypeaheadOrganisationSerializer(organisations, many=True).data
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
Invalid periods from targetsAt = period stay invalid in targetsAt = indicator
# Scenario

Given a program / parent project and a child project.

 - Add "DGIS IATI" to the program's validation sets (this doesn't work in a clean env #4777)
![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/5117da12-74db-408c-9f26-830faa615e09)
 - Set the program's "targets at" to "period" ![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/f9ad297b-a2d7-4a4a-b2c2-bb6daca56d25)
 - Switch to child project:
   * Add a result (Outcome) > indicator (quantitative) > period
   * Leave the period's **Target value** unchanged and red, but fill in all other mandatory fields (of indicator and result) ![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/59e1603d-9d92-479d-95e1-9c76f56aa765)
 - Change the program's "targets at" to "indicator" ![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/e5b5dd30-4d2e-4edc-bb0e-8303ba9a8f39)
 - Navigate to the created period in the child project

## Results

### Expected

The period is now valid as the target value is at indicator level

### Actual

The period is invalid and red in the UI

![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/0c562c1f-8851-42c3-8328-e4bc740fd206)

# Possible sources

 - The field might just be hidden in the UI but still evaluated: https://github.com/akvo/akvo-rsr/blob/bb01e875a25425ae19a10790d4313f382216bb3e/akvo/rsr/spa/app/modules/editor/section5/periods/targets.jsx#L58


Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py
--- a/akvo/rsr/models/project.py
+++ b/akvo/rsr/models/project.py
@@ -509,6 +509,11 @@ def save(self, *args, **kwargs):
                 self.iati_status = self.STATUS_TO_CODE[self.status]
                 super(Project, self).save(update_fields=['iati_status'])
 
+            # Root project with modified targets_at must propagate change to children
+            if self.targets_at != orig.targets_at and hasattr(self, "projecthierarchy"):
+                descendants = self.descendants()
+                descendants.exclude(pk=self.pk).update(targets_at=self.targets_at)
+
             orig_aggregate_children = orig.aggregate_children
             orig_aggregate_to_parent = orig.aggregate_to_parent
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
Missing comma in `__all__` results in unexpected string concatenation
Line 71 has a missing comma resulting in unwanted implicit string concatenation:

https://github.com/akvo/akvo-rsr/blob/945f2d763e2709d56b75d4d681ddbeb183903a69/akvo/rsr/views/py_reports/__init__.py#L69-L73

this results in `'render_program_period_lables_overview'` being concatenated with `'render_nuffic_country_level_report'` so python tries to expose the variable named `'render_program_period_lables_overviewrender_nuffic_country_level_report'` (which of course does not exist)

so if a dev tried ` from akvo.views.py_reports import *` then an `AttributeError` would occur (`__all__` affects the `from <module> import *` behavior only.)

I can make a PR fixing this for you?


Discussion:
Tangentially related: these two lines seem to have an unwanted comma at the end of the line, resulting in the value evaluating to a tuple. 

https://github.com/akvo/akvo-rsr/blob/945f2d763e2709d56b75d4d681ddbeb183903a69/akvo/rsr/tests/results_framework/test_results_framework.py#L237
https://github.com/akvo/akvo-rsr/blob/945f2d763e2709d56b75d4d681ddbeb183903a69/akvo/rsr/tests/results_framework/test_results_framework.py#L273

Is that unexpected behaviour? I can fix this too in the same PR if so

Resolving patch:
diff --git a/akvo/rsr/views/py_reports/__init__.py b/akvo/rsr/views/py_reports/__init__.py
--- a/akvo/rsr/views/py_reports/__init__.py
+++ b/akvo/rsr/views/py_reports/__init__.py
@@ -68,6 +68,6 @@ def check(request):
     'render_org_projects_overview_report',
     'render_program_overview_excel_report',
     'render_program_overview_pdf_report',
-    'render_program_period_lables_overview'
+    'render_program_period_lables_overview',
     'render_nuffic_country_level_report',
 ]


Test patch:
diff --git a/akvo/rsr/tests/results_framework/test_results_framework.py b/akvo/rsr/tests/results_framework/test_results_framework.py
--- a/akvo/rsr/tests/results_framework/test_results_framework.py
+++ b/akvo/rsr/tests/results_framework/test_results_framework.py
@@ -234,7 +234,7 @@ def test_child_indicator_state_updates_after_change(self):
         self.indicator.measure = "2"
         # # these properties were not set already, and hence should be updated too
         self.indicator.baseline_year = 2010
-        self.indicator.baseline_value = 'value',
+        self.indicator.baseline_value = 'value'
         self.indicator.baseline_comment = 'comment'
         self.indicator.export_to_iati = False
         self.indicator.scores = ['Good', 'Bad', 'Ugly']
@@ -270,7 +270,7 @@ def test_child_indicator_state_not_overwritten_after_change(self):
 
         # When
         self.indicator.baseline_year = 2010
-        self.indicator.baseline_value = 'value',
+        self.indicator.baseline_value = 'value'
         self.indicator.baseline_comment = 'comment'
         self.indicator.save()
Repository: akvo/akvo-rsr

Issue:
Clean dev envs can't create programs in the frontend
After starting a clean, local environment with `docker-compose up -d` and logging in, the bar to create programs is missing in the frontend.

![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/eee44ac0-094a-43f6-b8d1-d5d6784ff3f6)

One first has to go to the admin interface and [add a program](http://localhost/en/admin/rsr/projecthierarchy/add/)

![image.png](https://images.zenhubusercontent.com/615f039319c1f837a3cdece3/0f7c50ff-1f07-424c-9e0e-975ecce19ae5)

Once that is done, the feature is available in the frontend.


Discussion:

Resolving patch:
diff --git a/akvo/rsr/management/commands/populate_local_db.py b/akvo/rsr/management/commands/populate_local_db.py
--- a/akvo/rsr/management/commands/populate_local_db.py
+++ b/akvo/rsr/management/commands/populate_local_db.py
@@ -23,7 +23,7 @@ def handle(self, *args, **options):
         user = BaseTestCase.create_user(
             email='local@akvo.org', password='password', is_admin=True, is_superuser=True)
         org = BaseTestCase.create_organisation('Akvo Foundation')
-        project = BaseTestCase.create_project('Akvo RSR Test')
+        project = BaseTestCase.create_program('Akvo RSR Test', org=org)
         self.add_fake_project_image(project)
         BaseTestCase.make_org_admin(user, org)
         BaseTestCase.make_partner(project, org, role=Partnership.IATI_REPORTING_ORGANISATION)


Test patch:
diff --git a/akvo/rsr/tests/base.py b/akvo/rsr/tests/base.py
--- a/akvo/rsr/tests/base.py
+++ b/akvo/rsr/tests/base.py
@@ -149,7 +149,7 @@ def make_project_role(user, project, group_name):
         return ProjectRole.objects.create(user=user, project=project, group=group)
 
     @staticmethod
-    def create_program(title, org=None):
+    def create_program(title, org=None) -> Project:
         if org is None:
             org = BaseTestCase.create_organisation('Akvo')
         program = BaseTestCase.create_project(title)
Repository: akvo/akvo-rsr

Issue:
Don't send IATI import emails to admins



Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/iati_import_job.py b/akvo/rsr/models/iati_import_job.py
--- a/akvo/rsr/models/iati_import_job.py
+++ b/akvo/rsr/models/iati_import_job.py
@@ -14,7 +14,6 @@
 import tablib
 from lxml import etree
 
-from django.conf import settings
 from django.contrib.admin.models import LogEntry
 from django.contrib.contenttypes.models import ContentType
 from django.core.files import File
@@ -195,12 +194,10 @@ def get_log_csv(self, type):
 
     def send_mail(self):
         """
-        Send an email to the RSR admins (gathered from settings) and the user linked to the
-        IATI import instance.
+        Send an email to the user linked to the IATI import instance.
         """
 
-        email_addresses = [email for _name, email in settings.ADMINS]
-        email_addresses.append(self.iati_import.user.email)
+        email_addresses = [self.iati_import.user.email]
 
         attachments = []
         attachments.extend(self.get_log_csv(self.CRITICAL_LOG))


Test patch:
Repository: akvo/akvo-rsr

Issue:
Feature Request: Modification to Optimy integration script: default 'Unpublished' status 
### What are you trying to do?

Modify the current Optimy integration script for Aqua for All's 'Making Water Count' programme. 


### Describe the solution you'd like

All projects created in RSR via the Optimy integration have a default status of ‘unpublished; the Aqua for All team is responsible to manually ‘publish’ ALL projects. 


### Have you consider alternatives?

This is the best option after review. 

### Additional context

_No response_
Feature Request: Modification to Optimy integration script: default 'Unpublished' status 
### What are you trying to do?

Modify the current Optimy integration script for Aqua for All's 'Making Water Count' programme. 


### Describe the solution you'd like

All projects created in RSR via the Optimy integration have a default status of ‘unpublished; the Aqua for All team is responsible to manually ‘publish’ ALL projects. 


### Have you consider alternatives?

This is the best option after review. 

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/akvo/rsr/management/commands/a4a_optimy_import.py b/akvo/rsr/management/commands/a4a_optimy_import.py
--- a/akvo/rsr/management/commands/a4a_optimy_import.py
+++ b/akvo/rsr/management/commands/a4a_optimy_import.py
@@ -284,9 +284,6 @@ def create_project(project, answers):
         else:
             print(f"Could not find iso code for {name}")
 
-    # Publish the project
-    project.publish()
-
     return project
 
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
Modifications for Optimy Integration Script: default validation set
### What are you trying to do?

Modify the Optimy integration script so that is automatically sets the validation set. 

### Describe the solution you'd like

For all new projects being created in RSR via the Optimy integration strict, the ‘MWC modified’ validation set is the default setting. 

### Have you consider alternatives?

n/a

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/akvo/rsr/management/commands/a4a_optimy_import.py b/akvo/rsr/management/commands/a4a_optimy_import.py
--- a/akvo/rsr/management/commands/a4a_optimy_import.py
+++ b/akvo/rsr/management/commands/a4a_optimy_import.py
@@ -28,7 +28,7 @@
     Partnership,
     Project,
     ProjectCustomField,
-    ProjectLocation,
+    ProjectEditorValidationSet, ProjectLocation,
 )
 from akvo.utils import custom_get_or_create_country
 
@@ -84,6 +84,7 @@
     "default_tied_status": "3",
     "default_finance_type": "110",
 }
+VALIDATION_SET_NAME = "DGIS Modified"
 
 
 def programs_exist():
@@ -173,6 +174,10 @@ def create_project(project, answers):
             defaults=dict(value=project_id, section="1", order="1"),
         )
 
+        validation_set = ProjectEditorValidationSet.objects.filter(name=VALIDATION_SET_NAME).first()
+        if validation_set:
+            project.validations.add(validation_set)
+
     program = Project.objects.get(pk=lead_project_id)
     project.add_to_program(program)
     # Add Aqua for All as financing partner


Test patch:
Repository: akvo/akvo-rsr

Issue:
Bug: Locations are reset on some projects
### What were you doing?

A client has reported that on some random projects after the location has been set, the locations are reset within a few hours. The occurrence has mostly been observed within 24h of making the modification.

### What should've happened?

Locations (and other fields) should magically be reset.

### My environment

_No response_

### Additional context

This particular client has a nightly script that pulls information from an external system, of which location is a part. However, the script only modifies locations of newly created projects.

Possibilities:

 - something is deeply wrong with Django and after a project is created it doesn't say it's created (highly unlikely)
 - the script has nothing to do with it and it's
   * human error
   * a bug in the frontend e.g changes are cached and when a user gets access to the network again the changes are pushed (React?)
   * a side effect in the backend or another script


Discussion:
The first step will be to be tracking modifications to that specific field. If it changes, we should log it.
It should be configurable which fields we track so that in the future, only a small change will be necessary.

Resolving patch:
diff --git a/akvo/rsr/models/location.py b/akvo/rsr/models/location.py
--- a/akvo/rsr/models/location.py
+++ b/akvo/rsr/models/location.py
@@ -3,9 +3,11 @@
 # Akvo RSR is covered by the GNU Affero General Public License.
 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
-
+import logging
 
 from django.db import models
+from django.db.models.signals import pre_delete
+from django.dispatch import receiver
 from django.utils.translation import ugettext_lazy as _
 
 from ..fields import LatitudeField, LongitudeField, ValidXMLCharField
@@ -213,9 +215,20 @@ def iati_designation_unicode(self):
     'The country or countries that benefit(s) from the activity.'
 )
 
+logger = logging.getLogger(__name__)
+
+
+@receiver(pre_delete, sender=ProjectLocation)
+def on_projectlocation_delete(sender, instance: ProjectLocation, using, **kwargs):
+    logger.warning(
+        "About to delete ProjectLocation(%s) %s of project(%s) %s",
+        instance.id, instance,
+        instance.location_target.id, instance.location_target,
+        stack_info=True
+    )
 
-class AdministrativeLocation(models.Model):
 
+class AdministrativeLocation(models.Model):
     project_relation = 'locations__administratives__in'
 
     location = models.ForeignKey(


Test patch:
Repository: akvo/akvo-rsr

Issue:
Bug: module 'django.db.models' has no attribute 'FieldDoesNotExist'
### What were you doing?

Adding a new organisation failed with HTTP 500 response

### What should've happened?

Should be able to add a new organisation

### My environment

_No response_

### Additional context

https://sentry.io/organizations/akvo-foundation/issues/2963583513/?project=218288


Discussion:

Resolving patch:
diff --git a/akvo/rsr/admin.py b/akvo/rsr/admin.py
--- a/akvo/rsr/admin.py
+++ b/akvo/rsr/admin.py
@@ -8,6 +8,7 @@
 
 
 from django import forms
+from django.core.exceptions import FieldDoesNotExist
 from django.contrib import admin
 from django.contrib.admin import helpers, widgets
 from django.contrib.admin.options import IS_POPUP_VAR
@@ -362,7 +363,7 @@ def add_view(self, request, form_url='', extra_context=None):
             for k in initial:
                 try:
                     f = opts.get_field(k)
-                except models.FieldDoesNotExist:
+                except FieldDoesNotExist:
                     continue
                 if isinstance(f, models.ManyToManyField):
                     initial[k] = initial[k].split(",")


Test patch:
Repository: akvo/akvo-rsr

Issue:
Duplicate Dutch foreign ministry org
At some point in time, the Dutch foreign ministry was duplicated in the RSR database, which is causing problems when clients want to partner with the ministry. They find two and don't know which one to pick.

This is a cleanup task to point all the partners to the actual Dutch ministry.


> Dutch Ministry of Foreign Affairs (ID #464)
> partner of 1526 projects
> 1 employee

> Netherlands Ministry of Foreign Affairs (ID #4596)
> partner of 125 projects
> 0 employee


Discussion:

Resolving patch:
diff --git a/akvo/rsr/management/commands/remote_netherlands_foreign_ministry.py b/akvo/rsr/management/commands/remote_netherlands_foreign_ministry.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/management/commands/remote_netherlands_foreign_ministry.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+# Akvo Reporting is covered by the GNU Affero General Public License.
+# See more details in the license.txt file located at the root folder of the Akvo RSR module.
+# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
+import warnings
+
+from django.core.management.base import BaseCommand
+from django.db import transaction
+
+from akvo.rsr.models import (
+    Organisation,
+)
+
+
+class Command(BaseCommand):
+    help = "Remove Netherlands Foreign Ministry which is a duplicate of the Dutch Foreign Ministry"
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            "--dry-run", action="store_true", help="No action will be taken in the DB"
+        )
+
+    def handle(self, *args, **options):
+        try:
+            with warnings.catch_warnings():
+                warnings.simplefilter("ignore")
+                self._handle(*args, **options)
+        except InterruptedError:
+            print("DRY RUN: No action was taken")
+
+    @transaction.atomic()
+    def _handle(self, *args, **options):
+        dry_run = options.get("dry_run")
+        if dry_run:
+            print("DRY RUN: No action will be taken")
+
+        original_org = Organisation.objects.get(id=464)
+        duplicate_org = Organisation.objects.get(id=4596)
+
+        self.stdout.write("Migrating partnerships of '%s' to '%s'" % (duplicate_org, original_org))
+        for partnership in duplicate_org.partnerships.all().order_by("project__id"):
+            partnership.organisation = original_org
+            partnership.save()
+            project = partnership.project
+            self.stdout.write("\tPartnership(%s): %s - %s" % (partnership.id, project.id, project.title))
+
+        self.stdout.write("Deleting org '%s'" % (duplicate_org, ))
+        duplicate_org.delete()
+
+        if dry_run:
+            raise InterruptedError()


Test patch:
Repository: akvo/akvo-rsr

Issue:
Bug: Password protected partner sites
### What were you doing?

Users are not prompted to enter the password for the password-protected partner sites.

### What should've happened?

The password page should be displayed when the user is trying to access password-protected partner sites.

### My environment

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/akvo/rsr/views/__init__.py b/akvo/rsr/views/__init__.py
--- a/akvo/rsr/views/__init__.py
+++ b/akvo/rsr/views/__init__.py
@@ -14,3 +14,18 @@ def index(request):
     """Redirect user to project directory or My RSR."""
 
     return HttpResponseRedirect(reverse('project-directory', args=[]))
+
+
+def lockpass(request):
+    """Endpoint to make the password-protected partner site useable for users.
+
+    This is a hack that utilizes the Django-lockdown mechanism to prompt the password page
+    for password-protected partner sites.
+
+    See: akvo.rsr.middleware.RSRLockdownMiddleware
+    """
+
+    next_page = request.GET.get("next")
+    return HttpResponseRedirect(
+        next_page if next_page else reverse("project-directory", args=[])
+    )
diff --git a/akvo/urls.py b/akvo/urls.py
--- a/akvo/urls.py
+++ b/akvo/urls.py
@@ -46,6 +46,10 @@
     url(r'^$',
         views.index, name='index'),
 
+    # Hack to prompt password on password-protected partner sites
+    url(r'^lockpass/$',
+        views.lockpass, name='lockpass'),
+
     # Projects
     url(r'^projects/$',
         project.directory, name='project-directory'),


Test patch: