internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Pylons/pyramid

Issue:
stop overriding certain webob properties like json_body
pyramid defined `request.json_body` before webob, but now webob has a better impl than pyramid and it can't be used. We should remove the impl and rely on inheriting the behavior from webob. There may be other attributes like this as well.


Discussion:

Resolving patch:
diff --git a/src/pyramid/request.py b/src/pyramid/request.py
--- a/src/pyramid/request.py
+++ b/src/pyramid/request.py
@@ -1,5 +1,4 @@
 from collections import deque
-import json
 
 from zope.interface import implementer
 from zope.interface.interface import InterfaceClass
@@ -229,10 +228,6 @@ def is_response(self, ob):
             return False
         return adapted is ob
 
-    @property
-    def json_body(self):
-        return json.loads(text_(self.body, self.charset))
-
 
 def route_request_iface(name, bases=()):
     # zope.interface treats the __name__ as the __doc__ and changes __name__


Test patch:
Repository: Pylons/pyramid

Issue:
pserve configures logging twice when using --reload
pserve invokes `loader.setup_logging()` before invoking `hupper.start_reloader` which configures logging in the monitor process **and** then later configures it again in the child/worker/app process.

We should, instead, invoke `basicConfig` if `--reload` is set and hupper is not active yet such that the parent process just logs to stderr instead of using the logging config intended for the app itself.

See https://groups.google.com/d/msgid/pylons-discuss/098b16e7-1955-4d21-9f4c-6a32d82fe103%40googlegroups.com


Discussion:

Resolving patch:
diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py
--- a/src/pyramid/scripts/pserve.py
+++ b/src/pyramid/scripts/pserve.py
@@ -182,7 +182,11 @@ def run(self):  # pragma: no cover
         app_name = self.args.app_name
 
         loader = self._get_config_loader(config_uri)
-        loader.setup_logging(config_vars)
+
+        # setup logging only in the worker process incase the logging config
+        # opens files which should not be opened by multiple processes at once
+        if not self.args.reload or hupper.is_active():
+            loader.setup_logging(config_vars)
 
         self.pserve_file_config(loader, global_conf=config_vars)
 


Test patch:
Repository: Pylons/pyramid

Issue:
pserve configures logging twice when using --reload
pserve invokes `loader.setup_logging()` before invoking `hupper.start_reloader` which configures logging in the monitor process **and** then later configures it again in the child/worker/app process.

We should, instead, invoke `basicConfig` if `--reload` is set and hupper is not active yet such that the parent process just logs to stderr instead of using the logging config intended for the app itself.

See https://groups.google.com/d/msgid/pylons-discuss/098b16e7-1955-4d21-9f4c-6a32d82fe103%40googlegroups.com


Discussion:

Resolving patch:
diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py
--- a/src/pyramid/scripts/pserve.py
+++ b/src/pyramid/scripts/pserve.py
@@ -184,7 +184,11 @@ def run(self):  # pragma: no cover
         app_name = self.args.app_name
 
         loader = self._get_config_loader(config_uri)
-        loader.setup_logging(config_vars)
+
+        # setup logging only in the worker process incase the logging config
+        # opens files which should not be opened by multiple processes at once
+        if not self.args.reload or hupper.is_active():
+            loader.setup_logging(config_vars)
 
         self.pserve_file_config(loader, global_conf=config_vars)
 


Test patch:
Repository: Pylons/pyramid

Issue:
pserve configures logging twice when using --reload
pserve invokes `loader.setup_logging()` before invoking `hupper.start_reloader` which configures logging in the monitor process **and** then later configures it again in the child/worker/app process.

We should, instead, invoke `basicConfig` if `--reload` is set and hupper is not active yet such that the parent process just logs to stderr instead of using the logging config intended for the app itself.

See https://groups.google.com/d/msgid/pylons-discuss/098b16e7-1955-4d21-9f4c-6a32d82fe103%40googlegroups.com


Discussion:

Resolving patch:
diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py
--- a/pyramid/scripts/pserve.py
+++ b/pyramid/scripts/pserve.py
@@ -165,7 +165,11 @@ def run(self):  # pragma: no cover
         app_name = self.args.app_name
 
         loader = self._get_config_loader(config_uri)
-        loader.setup_logging(config_vars)
+
+        # setup logging only in the worker process incase the logging config
+        # opens files which should not be opened by multiple processes at once
+        if not self.args.reload or hupper.is_active():
+            loader.setup_logging(config_vars)
 
         self.pserve_file_config(loader, global_conf=config_vars)
 


Test patch:
Repository: Pylons/pyramid

Issue:
DeprecationWarning: the imp module is deprecated in favour of importlib
## Bug Report

**Describe the bug**
After generating a Pyramid project from the master branch of the pyramid-cookiecutter-starter and running tests, a DeprecationWarning is output:

`DeprecationWarning: the imp module is deprecated in favour of importlib ; see the module's documentation for alternative uses import imp`

**To Reproduce**
Run through the steps starting at https://docs.pylonsproject.org/projects/pyramid/en/master/narr/project.html#creating-the-project and end with running tests.

**Expected behavior**
No deprecation warning.

**Additional context**
These lines need to be updated:
https://github.com/Pylons/pyramid/blob/323cfbb45e6ee4b7462bbea9dcaa4e8258dd74f6/src/pyramid/path.py#L4-L15

I'm not sure how to fix this one. `imp.get_suffixes()` and `imp.C_EXTENSION` and `imp.C_BUILTIN` don't have clear replacements in `importlib`. I'm guessing it has something to do with [`importlib.machinery.all_suffixes()`](https://docs.python.org/3/library/importlib.html#importlib.machinery.all_suffixes), [`importlib.machinery.EXTENSION_SUFFIXES`](https://docs.python.org/3/library/importlib.html#importlib.machinery.EXTENSION_SUFFIXES), or [`importlib.machinery.SOURCE_SUFFIXES`](https://docs.python.org/3/library/importlib.html#importlib.machinery.SOURCE_SUFFIXES)?


Discussion:

Resolving patch:
diff --git a/src/pyramid/path.py b/src/pyramid/path.py
--- a/src/pyramid/path.py
+++ b/src/pyramid/path.py
@@ -1,18 +1,13 @@
+from importlib.machinery import SOURCE_SUFFIXES
 import os
 import pkg_resources
 import sys
-import imp
 
 from zope.interface import implementer
 
 from pyramid.interfaces import IAssetDescriptor
 
-ignore_types = [imp.C_EXTENSION, imp.C_BUILTIN]
-init_names = [
-    '__init__%s' % x[0]
-    for x in imp.get_suffixes()
-    if x[0] and x[2] not in ignore_types
-]
+init_names = ['__init__%s' % x for x in SOURCE_SUFFIXES]
 
 
 def caller_path(path, level=2):


Test patch:
Repository: Pylons/pyramid

Issue:
threading.Thread.setDaemon has been deprecated in favor of setting daemon attribute directly in Python 3.10
https://github.com/Pylons/pyramid/blob/8061fce297cc7117d3e6e2b39e47512c7db2904f/src/pyramid/scripts/pserve.py#L234


Ref : python/cpython#25174


Discussion:
@tirkarthi thank you for the report. Would you please submit a PR with a fix? There are dozens of fixes linked to that issue to choose from.

Resolving patch:
diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py
--- a/src/pyramid/scripts/pserve.py
+++ b/src/pyramid/scripts/pserve.py
@@ -231,7 +231,7 @@ def open_browser():
                     webbrowser.open(url)
 
                 t = threading.Thread(target=open_browser)
-                t.setDaemon(True)
+                t.daemon = True
                 t.start()
 
         if self.args.reload and not hupper.is_active():


Test patch:
Repository: Pylons/pyramid

Issue:
getargspec and formatspec were removed in Python 3.11
https://github.com/Pylons/pyramid/blob/0b24ac16cc04746b25cf460f1497c157f6d3d6f4/docs/conf.py#L395-L398


https://docs.python.org/3.11/whatsnew/3.11.html#removed

> the getargspec function, deprecated since Python 3.0; use inspect.signature() or inspect.getfullargspec() instead.
> the formatargspec function, deprecated since Python 3.5; use the inspect.signature() function and Signature object directly.


Discussion:
@tirkarthi thank you for the report. Would you please submit a pull request with a suggested change? The pull request should be made against both `master` and `2.0-branch`, as those are the versions that dropped Python 2 support.
@stevepiercy I guess this is something that could be easily compatted for previous version too.
@ztane it could, but I think we avoid adding a new version of Python to support for already released versions of Python. I think it's at the discretion of @mmerickel.

At the other end, we have a policy against removing supported older versions of Python at https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/upgrading.html#python-support-policy. I think it would be good to include what we do about adding new versions of Python to support.
I don't think there's any compatibility concerns here because it only affects the docs. We can just make the switch as we expect the docs to only compile on python 3 at this point via our rtd config.

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -14,7 +14,6 @@
 import sys
 import os
 import datetime
-import inspect
 import warnings
 
 warnings.simplefilter('ignore', DeprecationWarning)
@@ -385,19 +384,7 @@ def setup(app):
     app.add_directive('frontmatter', FrontMatter)
     app.add_directive('mainmatter', MainMatter)
     app.add_directive('backmatter', BackMatter)
-    app.connect('autodoc-process-signature', resig)
-
-
-def resig(app, what, name, obj, options, signature, return_annotation):
-    """ Allow for preservation of ``@action_method`` decorated methods
-    in configurator """
-    docobj = getattr(obj, '__docobj__', None)
-    if docobj is not None:
-        argspec = inspect.getargspec(docobj)
-        if argspec[0] and argspec[0][0] in ('cls', 'self'):
-            del argspec[0][0]
-        signature = inspect.formatargspec(*argspec)
-    return signature, return_annotation
+
 
 # turn off all line numbers in latex formatting
 


Test patch:
Repository: Pylons/pyramid

Issue:
Remove possibly obsolete Python 3.5 code?
While sniffing around for `action_method` for https://github.com/Pylons/pyramid/pull/3696, I stumbled across a potentially obsolete check for Python 3.5.0.

https://github.com/Pylons/pyramid/blob/6966401de04be64906f40e6fc6a2cf138cb7d3ca/src/pyramid/config/actions.py#L561-L567


Discussion:

Resolving patch:
diff --git a/src/pyramid/config/actions.py b/src/pyramid/config/actions.py
--- a/src/pyramid/config/actions.py
+++ b/src/pyramid/config/actions.py
@@ -557,13 +557,6 @@ def wrapper(self, *arg, **kw):
         if info is None:
             try:
                 f = traceback.extract_stack(limit=4)
-
-                # Work around a Python 3.5 issue whereby it would insert an
-                # extra stack frame. This should no longer be necessary in
-                # Python 3.5.1
-                last_frame = ActionInfo(*f[-1])
-                if last_frame.function == 'extract_stack':  # pragma: no cover
-                    f.pop()
                 info = ActionInfo(*f[-backframes])
             except Exception:  # pragma: no cover
                 info = ActionInfo(None, 0, '', '')


Test patch:
Repository: django-import-export/django-import-export

Issue:
Column names with spaces
Can't use column names with spaces - at least, as far as I could tell.

If this is indeed the case, and I'm not just being stupid, the fix is in resources.py at line 299.

```
    method = getattr(self, 'dehydrate_%s' % field.column_name, None)
```

becomes

```
    method = getattr(self, 'dehydrate_%s' % field.column_name.replace(' ', '_'), None)
```

Current use cases should be unaffected by that change.



Discussion:
Hi, it looks like we should use `attribute_name` instead of `column_name`. `attribute_name`:

```
method = getattr(self, 'dehydrate_%s' % field.column_name, None)
```

I have to test this, but would appreciate if you can test that this work for your case.

regards

That was my initial thought, too,  but attribute_name might be blank, and that led me down the road of testing for a value. Given that I wasn't too familiar with the internals of import_export, the  replace seemed an easier fix at the time.

Also, the use case for me is generating an export report (of sorts) for non-technical users, and being able to specify the column name in a very verbose way (i.e. more descriptive than what I name my attributes) is a requirement.

@pwr905 I am almost sure that `attribute_name` should be used in `dehydrate`but I will have catch some time  to dig in code and test it does not break anything. 


Resolving patch:
diff --git a/import_export/resources.py b/import_export/resources.py
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -112,6 +112,17 @@ def get_fields(self):
         """
         return [self.fields[f] for f in self.get_export_order()]
 
+    @classmethod
+    def get_field_name(cls, field):
+        """
+        Returns field name for given field.
+        """
+        for field_name, f in cls.fields.items():
+            if f == field:
+                return field_name
+        raise AttributeError("Field %s does not exists in %s resource" % (
+            field, cls))
+
     def init_instance(self, row=None):
         raise NotImplementedError()
 
@@ -296,7 +307,8 @@ def get_export_order(self):
         return self._meta.export_order or self.fields.keys()
 
     def export_field(self, field, obj):
-        method = getattr(self, 'dehydrate_%s' % field.column_name, None)
+        field_name = self.get_field_name(field)
+        method = getattr(self, 'dehydrate_%s' % field_name, None)
         if method is not None:
             return method(obj)
         return field.export(obj)


Test patch:
diff --git a/tests/core/tests/resources_tests.py b/tests/core/tests/resources_tests.py
--- a/tests/core/tests/resources_tests.py
+++ b/tests/core/tests/resources_tests.py
@@ -181,7 +181,7 @@ class Meta:
     def test_dehydrating_fields(self):
 
         class B(resources.ModelResource):
-            full_title = fields.Field()
+            full_title = fields.Field(column_name="Full title")
 
             class Meta:
                 model = Book
Repository: django-import-export/django-import-export

Issue:
unicode import
I kept getting errors on importing au unicode csv file. It seems to failing in the test dry_run on this line:
https://github.com/bmihelac/django-import-export/blob/master/import_export/resources.py#L342

after changing it to 
 row_result.object_repr = repr(instance)
it continues.



Discussion:
@jeee can you check if it raises error with

```
row_result.object_repr = force_text(instance)
```

Then I still get the error.

The string that could not be encoded/decoded was: OOO OÄOOOOO
'ascii' codec can't encode character u'\xc4' in position 17: ordinal not in range(128)

 /usr/local/lib/python2.7/dist-packages/import_export/resources.py in import_data
                            row_result.object_repr = force_text(instance)
/usr/lib/python2.7/dist-packages/django/utils/encoding.py in force_text
                        s = six.text_type(bytes(s), encoding, errors)

I should look into this. It would be helpful if you can make an minimal failing test case or example that fails.

Also please state version of python, django-import-export, django and tablib that you are using.


Resolving patch:
diff --git a/import_export/resources.py b/import_export/resources.py
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -341,7 +341,7 @@ def import_data(self, dataset, dry_run=False, raise_errors=False,
                         self.save_instance(instance, real_dry_run)
                         self.save_m2m(instance, row, real_dry_run)
                         # Add object info to RowResult for LogEntry
-                        row_result.object_repr = str(instance)
+                        row_result.object_repr = force_text(instance)
                         row_result.object_id = instance.pk
                     row_result.diff = self.get_diff(original, instance,
                             real_dry_run)


Test patch:
Repository: django-import-export/django-import-export

Issue:
In import_data, before_import should be called before the instance_loader is created
Currently, `import_data` looks like:

``` python
        instance_loader = self._meta.instance_loader_class(self, dataset)

        try:
            self.before_import(dataset, real_dry_run)
        except Exception as e:
            tb_info = traceback.format_exc(2)
            result.base_errors.append(Error(repr(e), tb_info))
            if raise_errors:
                if use_transactions:
                    transaction.rollback()
                    transaction.leave_transaction_management()
                raise
```

I have a situation where I need to add one of the `import_id_fields` to the dataset by calculating it from other fields, but the import crashes because CachedModelInstanceLoader I am using tries to access the field before I have added it to the dataset.

It would be better (for me at least) if it was:

``` python
        try:
            self.before_import(dataset, real_dry_run)
        except Exception as e:
            tb_info = traceback.format_exc(2)
            result.base_errors.append(Error(repr(e), tb_info))
            if raise_errors:
                if use_transactions:
                    transaction.rollback()
                    transaction.leave_transaction_management()
                raise

        instance_loader = self._meta.instance_loader_class(self, dataset)
```

I can't see any downside to doing this.



Discussion:
I'm happy to create a PR if you agree to the change. All tests still pass after making the change.

@rhunwicks yes, I think it is safe and expected to call `before_import` before everything else. So yes, please :)


Resolving patch:
diff --git a/import_export/resources.py b/import_export/resources.py
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -304,8 +304,6 @@ def import_data(self, dataset, dry_run=False, raise_errors=False,
         else:
             real_dry_run = dry_run
 
-        instance_loader = self._meta.instance_loader_class(self, dataset)
-
         try:
             self.before_import(dataset, real_dry_run)
         except Exception as e:
@@ -317,6 +315,8 @@ def import_data(self, dataset, dry_run=False, raise_errors=False,
                     transaction.leave_transaction_management()
                 raise
 
+        instance_loader = self._meta.instance_loader_class(self, dataset)
+
         for row in dataset.dict:
             try:
                 row_result = RowResult()


Test patch:
Repository: django-import-export/django-import-export

Issue:
Export order
Is there a way to specify a partial export order ? For example, I'd like to specify that the first two columns should be "id" and "name", then I'd like to have all remaining fields in whatever order.

Currently I have two options: 
- Specify `export_order` in the resource's meta object, but any field that is not listed will not be included;
- Not specify `export_order` in which case the export starts with the fields declared explicitly in the resource in no particular order followed by introspected fields in the order they were declared in the model.

Ideally, what I would like is to have introspected fields first in order of declaration, then explicit fields. Since other applications may have different requirements, I would be happy with specifying a couple of fields explicitly in `export_order` so that those fields will come first and in the specified order, then have any remaining fields come after in no particular order.



Discussion:
Since you can access all fields in `resource.fields` ordered dict so it should be easy enough to add fields not in `export_order` to the end of the list.  This would happen in`get_export_order` .
PR would be welcomed


Resolving patch:
diff --git a/import_export/resources.py b/import_export/resources.py
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -371,7 +371,8 @@ def import_data(self, dataset, dry_run=False, raise_errors=False,
         return result
 
     def get_export_order(self):
-        return self._meta.export_order or self.fields.keys()
+        order = tuple (self._meta.export_order or ())
+        return order + tuple (k for k in self.fields.keys() if k not in order)
 
     def export_field(self, field, obj):
         field_name = self.get_field_name(field)


Test patch:
diff --git a/tests/core/tests/resources_tests.py b/tests/core/tests/resources_tests.py
--- a/tests/core/tests/resources_tests.py
+++ b/tests/core/tests/resources_tests.py
@@ -33,6 +33,7 @@
 class MyResource(resources.Resource):
     name = fields.Field()
     email = fields.Field()
+    extra = fields.Field()
 
     class Meta:
         export_order = ('email', 'name')
@@ -57,7 +58,7 @@ def test_meta(self):
 
     def test_get_export_order(self):
         self.assertEqual(self.my_resource.get_export_headers(),
-                ['email', 'name'])
+                ['email', 'name', 'extra'])
 
 
 class BookResource(resources.ModelResource):
Repository: django-import-export/django-import-export

Issue:
admin.site.site_header not being honored in django 1.7
Hi when using django 1.7 and the new admin.site.site_header option import-export reverts to the default site_header value of Django Site Admin instead of the customized variable.
![screen shot 2015-02-22 at 7 04 49 pm](https://cloud.githubusercontent.com/assets/11152878/6321568/5d5b1eee-bac6-11e4-8837-1ee6c30f980b.png)
![screen shot 2015-02-22 at 7 04 53 pm](https://cloud.githubusercontent.com/assets/11152878/6321567/5d5818ca-bac6-11e4-81f5-d7dff6805c71.png)



Discussion:
PR welcome :)


Resolving patch:
diff --git a/import_export/admin.py b/import_export/admin.py
--- a/import_export/admin.py
+++ b/import_export/admin.py
@@ -4,6 +4,7 @@
 from datetime import datetime
 import os.path
 
+import django
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 from django.conf.urls import patterns, url
@@ -211,6 +212,11 @@ def import_action(self, request, *args, **kwargs):
                     'input_format': form.cleaned_data['input_format'],
                 })
 
+        if django.VERSION >= (1, 8, 0):
+            context.update(self.admin_site.each_context(request))
+        elif django.VERSION >= (1, 7, 0):
+            context.update(self.admin_site.each_context())
+
         context['form'] = form
         context['opts'] = self.model._meta
         context['fields'] = [f.column_name for f in resource.get_fields()]
@@ -324,6 +330,12 @@ def export_action(self, request, *args, **kwargs):
             return response
 
         context = {}
+
+        if django.VERSION >= (1, 8, 0):
+            context.update(self.admin_site.each_context(request))
+        elif django.VERSION >= (1, 7, 0):
+            context.update(self.admin_site.each_context())
+
         context['form'] = form
         context['opts'] = self.model._meta
         return TemplateResponse(request, [self.export_template_name],


Test patch: