internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: jazzband/django-simple-history

Issue:
Warn when using HistoricalRecords on an abstract class without inherit=True
Adding a `HistoricalRecords` to an abstract model without `inherit=True` unlike most other Field types doesn't do anything. It should therefore trigger a warning with a hint to `inherit=True`.

```python
class CommonFields(models.Model):
    history = HistoricalRecords()

    class Meta:
        abstract = True

class Foo(CommonFields):
    pass
```


Discussion:

Resolving patch:
diff --git a/simple_history/models.py b/simple_history/models.py
--- a/simple_history/models.py
+++ b/simple_history/models.py
@@ -4,6 +4,7 @@
 import importlib
 import threading
 import uuid
+import warnings
 
 from django.apps import apps
 from django.conf import settings
@@ -21,8 +22,8 @@
 from . import exceptions
 from .manager import HistoryDescriptor
 from .signals import (
-    pre_create_historical_record,
     post_create_historical_record,
+    pre_create_historical_record
 )
 
 registered_models = {}
@@ -71,6 +72,11 @@ def contribute_to_class(self, cls, name):
         models.signals.class_prepared.connect(self.finalize, weak=False)
         self.add_extra_methods(cls)
 
+        if cls._meta.abstract and not self.inherit:
+            msg = "HistoricalRecords added to abstract model ({}) without " \
+                  "inherit=True".format(self.cls.__name__)
+            warnings.warn(msg, UserWarning)
+
     def add_extra_methods(self, cls):
         def save_without_historical_record(self, *args, **kwargs):
             """


Test patch:
diff --git a/simple_history/tests/tests/test_models.py b/simple_history/tests/tests/test_models.py
--- a/simple_history/tests/tests/test_models.py
+++ b/simple_history/tests/tests/test_models.py
@@ -1048,3 +1048,22 @@ def test_changed_value_lost(self):
         historical = self.get_first_historical()
         instance = historical.instance
         self.assertEqual(instance.place, new_place)
+
+
+class WarningOnAbstractModelWithInheritFalseTest(TestCase):
+    def test_warning_on_abstract_model_with_inherit_false(self):
+
+        with warnings.catch_warnings(record=True) as w:
+            class AbstractModelWithInheritFalse(models.Model):
+                string = models.CharField()
+                history = HistoricalRecords()
+
+                class Meta:
+                    abstract = True
+
+            self.assertEqual(len(w), 1)
+            self.assertTrue(issubclass(w[0].category, UserWarning))
+            self.assertEqual(str(w[0].message),
+                             'HistoricalRecords added to abstract model '
+                             '(AbstractModelWithInheritFalse) without '
+                             'inherit=True')
Repository: jazzband/django-simple-history

Issue:
Admin template issues on django trunk 
**Describe the bug**
A clear and concise description of what the bug is.
When running the full suite of tests, we run into the following errors when testing against django trunk:
```
SystemCheckError: System check identified some issues:

ERRORS:
?: (admin.E404) 'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin application.
?: (admin.E406) 'django.contrib.messages' must be in INSTALLED_APPS in order to use the admin application.
```

We should fix these before the next release. 

**To Reproduce**
Steps to reproduce the behavior:
Run `tox` locally. 


Discussion:

Resolving patch:
diff --git a/runtests.py b/runtests.py
--- a/runtests.py
+++ b/runtests.py
@@ -25,6 +25,7 @@
     'django.contrib.auth',
     'django.contrib.sessions',
     'django.contrib.admin',
+    'django.contrib.messages',
 ]
 
 DEFAULT_SETTINGS = dict(
@@ -45,6 +46,7 @@
         'OPTIONS': {
             'context_processors': [
                 'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
             ]
         },
     }],


Test patch:
diff --git a/simple_history/tests/tests/test_admin.py b/simple_history/tests/tests/test_admin.py
--- a/simple_history/tests/tests/test_admin.py
+++ b/simple_history/tests/tests/test_admin.py
@@ -194,7 +194,7 @@ def test_history_user_on_save_in_admin(self):
         self.assertEqual(Poll.history.get().history_user, self.user)
 
         # Ensure polls saved on edit page in admin interface save correct user
-        change_page = changelist_page.click("Poll object")
+        change_page = changelist_page.click("Poll object", index=1)
         change_page.form.submit()
         self.assertEqual([p.history_user for p in Poll.history.all()],
                          [self.user, self.user])
Repository: jazzband/django-simple-history

Issue:
Showing history in admin causes n+1 queries for history_user
It need a select_related as far as i can tell. Will create a pr for it.


Discussion:

Resolving patch:
diff --git a/simple_history/admin.py b/simple_history/admin.py
--- a/simple_history/admin.py
+++ b/simple_history/admin.py
@@ -48,7 +48,9 @@ def history_view(self, request, object_id, extra_context=None):
         pk_name = opts.pk.attname
         history = getattr(model, model._meta.simple_history_manager_attribute)
         object_id = unquote(object_id)
-        action_list = history.filter(**{pk_name: object_id})
+        action_list = history.filter(**{pk_name: object_id}).select_related(
+            "history_user"
+        )
         history_list_display = getattr(self, "history_list_display", [])
         # If no history was found, see whether this object even exists.
         try:


Test patch:
Repository: jazzband/django-simple-history

Issue:
ModuleNotFoundError: No module named 'six'
**Describe the bug**
It looks as if the new version lacks the dependency on module six.

**To Reproduce**
Steps to reproduce the behavior:
1. pip install django-simple-history
2. python manage.py makemigrations

**Expected behavior**
A running system

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
 - OS: Linux Mint 
 - Browser (if applicable): chrome
 - Django Simple History Version: 2.7.1
 - Django Version: 2.2
 - Database Version: sqlite3

**Additional context**
Tested with an old and a new environment



Discussion:
Presumably, this can be fixed by adding

```
install_requires=[
    'six',
],
```

to setup.py

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,8 @@
 import simple_history
 
 tests_require = [
-    'Django>=1.11', 'WebTest==2.0.24', 'django-webtest==1.8.0', 'mock==1.0.1']
+    'Django>=1.11', 'WebTest==2.0.24', 'django-webtest==1.8.0', 'mock==1.0.1',
+    'six']
 
 setup(
     name='django-simple-history',
@@ -39,6 +40,7 @@
     ],
     python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
     tests_require=tests_require,
+    install_requires=["six"],
     include_package_data=True,
     test_suite='runtests.main',
 )
diff --git a/simple_history/__init__.py b/simple_history/__init__.py
--- a/simple_history/__init__.py
+++ b/simple_history/__init__.py
@@ -1,6 +1,6 @@
 from __future__ import unicode_literals
 
-__version__ = "2.7.1"
+__version__ = "2.7.2"
 
 
 def register(


Test patch:
Repository: jazzband/django-simple-history

Issue:
Using m2m_fields in inheritated models
**Problem Statement**
Access many-to-many fields of base model when using inheritance

**Describe the solution you'd like**
I have a question about using django-simple-history with models that support inheritation.

Basic example:

```
class Application(PolymorphicModel):
     users = ManyToManyField("User")
```

```
class SpecialApplication(Application):
     history=HistoricalRecords(m2m_fields=["users"]
```

This results in `AttributeError: 'str' object has no attribute 'name'`

I also tried using `m2m_fields=[Application.users]` but received `AttributeError: 'ManyToManyDescriptor' object has no attribute 'name'`.

How can I solve this?

**Additional context**

Edit: I am using Django Polymorphic for my base model, I don't know if this makes a difference, but I put it in the example.


The documentation says:

 
> You may also define these fields in a model attribute (by default on _history_m2m_fields). This is mainly used for inherited models. You can override the attribute name by setting your own m2m_fields_model_field_name argument on the HistoricalRecord instance.

But I have no real clue how to use this. Is there an example somewhere?


Discussion:

Resolving patch:
diff --git a/simple_history/models.py b/simple_history/models.py
--- a/simple_history/models.py
+++ b/simple_history/models.py
@@ -768,7 +768,10 @@ def get_m2m_fields_from_model(self, model):
             m2m_fields.update(getattr(model, self.m2m_fields_model_field_name))
         except AttributeError:
             pass
-        return [getattr(model, field.name).field for field in m2m_fields]
+        field_names = [
+            field if isinstance(field, str) else field.name for field in m2m_fields
+        ]
+        return [getattr(model, field_name).field for field_name in field_names]
 
 
 def transform_field(field):


Test patch:
diff --git a/simple_history/tests/models.py b/simple_history/tests/models.py
--- a/simple_history/tests/models.py
+++ b/simple_history/tests/models.py
@@ -190,7 +190,7 @@ class Meta:
 
 class PollChildBookWithManyToMany(PollParentWithManyToMany):
     books = models.ManyToManyField("Book", related_name="books_poll_child")
-    _history_m2m_fields = [books]
+    _history_m2m_fields = ["books"]
 
 
 class PollChildRestaurantWithManyToMany(PollParentWithManyToMany):
Repository: jazzband/django-simple-history

Issue:
Commit 61df0e2f5e90 introduced a requirement for asgiref 3.6.0+
In commit 61df0e2f5e90 the middleware started using function `iscoroutinefunction` from `asgiref.sync`. This function is introduced in version 3.6.0.

It seems that this commit also introduced a hard dependency on asgiref which previously didn't exist (the use in models.py is conditional).

The easy fix is to add a versioned requirement for asgiref.


Discussion:
As far as I've understood, we only use `asgiref` because it's what Django itself uses and [recommends using for async middleware](https://docs.djangoproject.com/en/4.2/topics/http/middleware/#asynchronous-support), and so we will only ever have the need to use [the exact same version as Django requires](https://github.com/django/django/blob/4.2.5/setup.cfg#L42). In other words, if Django changed its required `asgiref` version or stopped using it altogether, we would most likely (have to) follow suit.

Because of this, I'm not entirely sure why not adding `asgiref` to our requirements could be a problem; would you mind explaining? 🙂
Not all supported versions of Django require asgiref 3.6.0. As an obvious example, Django 3.2 requires asgiref 3.3.2: https://github.com/django/django/blob/3.2.21/setup.cfg#L45

The problem could also be solved by directly requiring Django 4.2, but that doesn't sound right to me.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -11,6 +11,8 @@
             "fallback_version": "0.0.0",
         },
         setup_requires=["setuptools_scm"],
+        # DEV: Remove `asgiref` when the minimum required Django version is 4.2
+        install_requires=["asgiref>=3.6"],
         description="Store model history and view/revert changes from admin site.",
         long_description="\n".join((readme.read(), changes.read())),
         long_description_content_type="text/x-rst",


Test patch:
diff --git a/requirements/test.txt b/requirements/test.txt
--- a/requirements/test.txt
+++ b/requirements/test.txt
@@ -1 +1,3 @@
 -r ./coverage.txt
+# DEV: Remove this requirement entirely when the minimum required Django version is 4.2
+asgiref>=3.6
Repository: jazzband/django-simple-history

Issue:
Django 5.0 support
Just an issue to keep track of the support status of: https://docs.djangoproject.com/en/5.0/releases/5.0/


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -39,8 +39,8 @@
             "Intended Audience :: Developers",
             "Framework :: Django",
             "Framework :: Django :: 3.2",
-            "Framework :: Django :: 4.1",
             "Framework :: Django :: 4.2",
+            "Framework :: Django :: 5.0",
             "Programming Language :: Python",
             "Programming Language :: Python :: 3",
             "Programming Language :: Python :: 3.8",
@@ -48,6 +48,7 @@
             "Programming Language :: Python :: 3.10",
             "Programming Language :: Python :: 3.11",
             "Programming Language :: Python :: 3.12",
+            "Programming Language :: Python :: 3.13",
             "License :: OSI Approved :: BSD License",
         ],
         python_requires=">=3.8",


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -11,20 +11,26 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12-dev']
-        django-version: ['3.2', '4.1', '4.2', 'main']
+        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev']
+        django-version: ['3.2', '4.2', '5.0', 'main']
 
         exclude:
+          # Exclude py3.8 and py3.9 for Django main and 5.0
+          - python-version: '3.8'
+            django-version: '5.0'
+          - python-version: '3.9'
+            django-version: '5.0'
           - python-version: '3.8'
             django-version: 'main'
-
           - python-version: '3.9'
             django-version: 'main'
 
+          # Exclude py3.11, py3.12 and py3.13 for Django 3.2
           - python-version: '3.11'
             django-version: '3.2'
-
-          - python-version: '3.12-dev'
+          - python-version: '3.12'
+            django-version: '3.2'
+          - python-version: '3.13-dev'
             django-version: '3.2'
 
     services:
@@ -115,7 +121,7 @@ jobs:
           # Install this project in editable mode, so that its package metadata can be queried
           pip install -e .
           # Install the latest minor version of Django we support
-          pip install Django==4.2
+          pip install Django==5.0
 
       - name: Check translation files are updated
         run: python -m simple_history.tests.generated_file_checks.check_translations
Repository: jazzband/django-simple-history

Issue:
m2m historical records are saved even when SIMPLE_HISTORY_ENABLED = False
**Describe the bug**
m2m relationships ignores the SIMPLE_HISTORY_ENABLED = False, even when disabled the library is still saving the historical record.
This is causing me some issue when loading Django fixture using loaddata

**To Reproduce**
Steps to reproduce the behavior:
1. set SIMPLE_HISTORY_ENABLED = False
2. save a m2m relationship
3. you will see the record in the historical DB


**Expected behavior**
If SIMPLE_HISTORY_ENABLED = False no historical record should be created for m2m relationship

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
 - OS: Ubuntu 22
 - Browser (if applicable): [e.g. chrome, safari]
 - Django Simple History Version: [e.g. 1.9.1]
 - Django Version: [e.g. 1.11.11]
 - Database Version: PostgreSQL 15



Discussion:

Resolving patch:
diff --git a/simple_history/models.py b/simple_history/models.py
--- a/simple_history/models.py
+++ b/simple_history/models.py
@@ -673,6 +673,8 @@ def get_change_reason_for_object(self, instance, history_type, using):
         return utils.get_change_reason_from_object(instance)
 
     def m2m_changed(self, instance, action, attr, pk_set, reverse, **_):
+        if not getattr(settings, "SIMPLE_HISTORY_ENABLED", True):
+            return
         if hasattr(instance, "skip_history_when_saving"):
             return
 


Test patch:
diff --git a/simple_history/tests/tests/test_models.py b/simple_history/tests/tests/test_models.py
--- a/simple_history/tests/tests/test_models.py
+++ b/simple_history/tests/tests/test_models.py
@@ -2411,6 +2411,22 @@ def test_skip_history(self):
         self.assertEqual(skip_poll.history.all().count(), 2)
         self.assertEqual(skip_poll.history.all()[0].places.count(), 2)
 
+    @override_settings(SIMPLE_HISTORY_ENABLED=False)
+    def test_saving_with_disabled_history_doesnt_create_records(self):
+        # 1 from `setUp()`
+        self.assertEqual(PollWithManyToMany.history.count(), 1)
+
+        poll = PollWithManyToMany.objects.create(
+            question="skip history?", pub_date=today
+        )
+        poll.question = "huh?"
+        poll.save()
+        poll.places.add(self.place)
+
+        self.assertEqual(poll.history.count(), 0)
+        # The count should not have changed
+        self.assertEqual(PollWithManyToMany.history.count(), 1)
+
     def test_diff_against(self):
         self.poll.places.add(self.place)
         add_record, create_record = self.poll.history.all()
Repository: django-cms/django-cms

Issue:
using Django-CMS hover httpS - admin / front-end editor issue 
In HTTPS mode the Django-CMS run but some action don't work. 
Some GET request are send in HTTP and NOT in HTTPS protocol. 

example that don't work:
- in admin page editor - action > add page, save page
- in front-end editor with tinymce - action > show HTML

I don't tested everything like plugin usage, but is certainly very important to run test in HTTPS mode to guarantee it work also on this mode! 



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -41,7 +41,7 @@
     version=cms.__version__,
     description='An Advanced Django CMS',
     long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
-    url='http://www.django-cms.org/',
+    url='https://www.django-cms.org/',
     license='BSD License',
     platforms=['OS Independent'],
     classifiers=CLASSIFIERS,


Test patch:
Repository: django-cms/django-cms

Issue:
Document the fact that the django-cms mptt must be removed after upgrade
Document the fact that the django-cms mptt must be removed after upgrade.



Discussion:

Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -551,6 +551,10 @@ def get_absolute_url(self, language=None, fallback=True):
                     home_pk = self.home_pk_cache
                 except NoHomeFound:
                     pass
+                """
+                this is pain slow! the code fetches all ancestors for all pages
+                and then checks if the root node is a home_pk, if yes, it cuts off the first path part.
+                """
                 ancestors = self.get_cached_ancestors(ascending=True)
                 # sometimes there are no ancestors
                 if len(ancestors) != 0:


Test patch:
diff --git a/cms/tests/page.py b/cms/tests/page.py
--- a/cms/tests/page.py
+++ b/cms/tests/page.py
@@ -460,6 +460,44 @@ def test_existing_overwrite_url(self):
             self.assertFalse(form.is_valid())
             self.assertTrue('overwrite_url' in form.errors)
         
+    def test_page_urls(self):
+        page1 = create_page('test page 1', 'nav_playground.html', 'en',
+            published=True)
+
+        page2 = create_page('test page 2', 'nav_playground.html', 'en',
+            published=True, parent=page1)
+
+        page3 = create_page('test page 3', 'nav_playground.html', 'en',
+            published=True, parent=page2)
+
+        page4 = create_page('test page 4', 'nav_playground.html', 'en',
+            published=True)
+
+        page5 = create_page('test page 5', 'nav_playground.html', 'en',
+            published=True, parent=page4)
+
+        self.assertEqual(page1.get_absolute_url(),
+            self.get_pages_root()+'')
+        self.assertEqual(page2.get_absolute_url(),
+            self.get_pages_root()+'test-page-2/')
+        self.assertEqual(page3.get_absolute_url(),
+            self.get_pages_root()+'test-page-2/test-page-3/')
+        self.assertEqual(page4.get_absolute_url(),
+            self.get_pages_root()+'test-page-4/')
+        self.assertEqual(page5.get_absolute_url(),
+            self.get_pages_root()+'test-page-4/test-page-5/')
+
+        page3 = self.move_page(page3, page1)
+        self.assertEqual(page3.get_absolute_url(),
+            self.get_pages_root()+'test-page-3/')
+
+        page5 = self.move_page(page5, page2)
+        self.assertEqual(page5.get_absolute_url(),
+            self.get_pages_root()+'test-page-2/test-page-5/')
+
+        page3 = self.move_page(page3, page4)
+        self.assertEqual(page3.get_absolute_url(),
+            self.get_pages_root()+'test-page-4/test-page-3/')
 
 
 class NoAdminPageTests(CMSTestCase):
Repository: django-cms/django-cms

Issue:
Make menus failfast when attributes are misstyped
when using the attribute `menu` on a Menu subclass, it should failfast to prevent developers from wasting countless hours to find the missing s.



Discussion:
Really? Or just added in frustration? :)

really. I'm pretty damn sure I'm not the only idiot who does this wrong


Resolving patch:
diff --git a/cms/apphook_pool.py b/cms/apphook_pool.py
--- a/cms/apphook_pool.py
+++ b/cms/apphook_pool.py
@@ -1,15 +1,16 @@
 # -*- coding: utf-8 -*-
-from cms.exceptions import AppAllreadyRegistered
+from cms.exceptions import AppAlreadyRegistered
 from cms.utils.django_load import load, iterload_objects
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
+import warnings
 
 class ApphookPool(object):
     def __init__(self):
         self.apps = {}
         self.discovered = False
         self.block_register = False
-        
+
     def discover_apps(self):
         if self.discovered:
             return
@@ -24,7 +25,7 @@ def discover_apps(self):
         else:
             load('cms_app')
         self.discovered = True
-        
+
     def clear(self):
         self.apps = {}
         self.discovered = False
@@ -33,11 +34,18 @@ def register(self, app):
         if self.block_register:
             return
         from cms.app_base import CMSApp
-        assert issubclass(app, CMSApp)
-        if app.__name__ in self.apps.keys():
-            raise AppAllreadyRegistered, "[%s] an cms app with this name is already registered" % app.__name__
-        self.apps[app.__name__] = app
-        
+        # validate the app
+        if not issubclass(app, CMSApp):
+            raise ImproperlyConfigured('CMS Apps must inherit '
+                                       'cms.app_base.CMSApp, %r does not' % app)
+        if hasattr(app, 'menu') and not app.menus:
+            warnings.warn("You define a 'menu' attribute on your CMS App %r, "
+                "but the 'menus' attribute is empty, did you make a typo?")
+        name = app.__name__
+        if name in self.apps.keys():
+            raise AppAlreadyRegistered, "[%s] an cms app with this name is already registered" % name
+        self.apps[name] = app
+
     def get_apphooks(self):
         self.discover_apps()
         hooks = []
@@ -47,7 +55,7 @@ def get_apphooks(self):
         # Unfortunately, we loose the ordering since we now have a list of tuples. Let's reorder by app_name:
         hooks = sorted(hooks, key=lambda hook: hook[1])
         return hooks
-    
+
     def get_apphook(self, app_name):
         self.discover_apps()
         try:
diff --git a/cms/exceptions.py b/cms/exceptions.py
--- a/cms/exceptions.py
+++ b/cms/exceptions.py
@@ -5,9 +5,11 @@ class PluginAlreadyRegistered(Exception):
 class PluginNotRegistered(Exception):
     pass
 
-class AppAllreadyRegistered(Exception):
+class AppAlreadyRegistered(Exception):
     pass
 
+AppAllreadyRegistered = AppAlreadyRegistered # backwards compatibility, will be dropped in 2.3
+
 class NotImplemented(Exception):
     pass
 


Test patch: