internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: marshmallow-code/webargs

Issue:
source, dest arguments not working with nested args
Nested arg parsing does not respect source, dest arguments.



Discussion:
Thanks for reporting @ewang . I will look into this soon.

I think it's for the same reason I mentioned in #39 . I have some ideas on how to fix, but it'll involve refactoring quite a bit of the current Parser module.

@ewang The nested args parsing  could use refactoring; PRs are welcome. =)


Resolving patch:
diff --git a/webargs/core.py b/webargs/core.py
--- a/webargs/core.py
+++ b/webargs/core.py
@@ -258,6 +258,14 @@ def _validate(self, name, value):
                         _raise_required(nested_arg, key)
                 else:
                     ret[key] = nested_arg.validated(key, val)
+
+                if ((nested_arg.default is not None) and
+                        (ret.get(key, Missing) is Missing)):
+                    ret[key] = nested_arg.default
+
+                if nested_arg.dest is not None:
+                    ret[nested_arg.dest] = ret[key]
+                    del ret[key]
         return ret
 
     def validated(self, name, value):


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -619,6 +619,24 @@ def test_parse_with_dest(web_request):
     parsed = parser.parse(args, web_request, locations=('json',))
     assert parsed == {'content_type': 'application/json'}
 
+def test_parse_nested_with_dest(web_request):
+    parser = MockRequestParser()
+
+    web_request.json = dict(nested_arg=dict(wrong='OK'))
+    args = dict(nested_arg=Arg(dict(wrong=Arg(dest='right'))))
+
+    parsed = parser.parse(args, web_request, locations=('json',))
+    assert parsed == dict(nested_arg=dict(right='OK'))
+
+def test_parse_nested_with_default(web_request):
+    parser = MockRequestParser()
+
+    web_request.json = dict(nested_arg=dict())
+    args = dict(nested_arg=Arg(dict(missing=Arg(default=False))))
+
+    parsed = parser.parse(args, web_request, locations=('json',))
+    assert parsed == dict(nested_arg=dict(missing=False))
+
 def test_metadata_can_be_stored_on_args():
     # Extra params are stored as metadata
     arg = Arg(int, description='Just a number.')
Repository: marshmallow-code/webargs

Issue:
Drop support for marshmallow 3 versions older than rc1
Remove compatibility code added in https://github.com/sloria/webargs/pull/330 to support marshmallow 3 beta versions.


Discussion:

Resolving patch:
diff --git a/webargs/core.py b/webargs/core.py
--- a/webargs/core.py
+++ b/webargs/core.py
@@ -325,7 +325,6 @@ def _on_validation_error(self, error, req, schema):
             kwargs["data"] = error.data
             if MARSHMALLOW_VERSION_INFO[0] < 3:
                 kwargs["fields"] = error.fields
-            if LooseVersion(ma.__version__) < LooseVersion("3.0.0rc1"):
                 kwargs["field_names"] = error.field_names
             else:
                 kwargs["field_name"] = error.field_name


Test patch:
Repository: marshmallow-code/webargs

Issue:
AttributeError: module 'typing' has no attribute 'NoReturn' with Python 3.5.3
I get this error when running the tests with Python 3.5.3.

```
tests/test_py3/test_aiohttpparser_async_functions.py:6: in <module>
    from webargs.aiohttpparser import parser, use_args, use_kwargs
webargs/aiohttpparser.py:72: in <module>
    class AIOHTTPParser(AsyncParser):
webargs/aiohttpparser.py:148: in AIOHTTPParser
    ) -> typing.NoReturn:
E   AttributeError: module 'typing' has no attribute 'NoReturn'
```

The docs say [`typing.NoReturn`](https://docs.python.org/3/library/typing.html#typing.NoReturn) was added in 3.6.5. However, [the tests pass on Travis](https://travis-ci.org/marshmallow-code/webargs/jobs/486701760) with Python 3.5.6.


Discussion:
Looks like this was a bug until 3.5.4rc1 : https://bugs.python.org/issue28556 .

@lafrech Can you upgrade your Python version?
Not really. https://packages.debian.org/search?keywords=python3

I could use pyenv to develop and run the tests. Still, people using Debian stable or any 3.5.3- version can't run the asyncio part of the code. I mean it is not only about me running the tests but also about anyone willing to run an application using the lib.

But as long as no one complains, maybe we can live with this until 3.6 or 3.7 is standard.
I see. I'd prefer not to support old patch versions Python, but we can live with removing the `typing.NoReturn` usages for now, at least until we decide to drop 3.5 support.

Resolving patch:
diff --git a/webargs/aiohttpparser.py b/webargs/aiohttpparser.py
--- a/webargs/aiohttpparser.py
+++ b/webargs/aiohttpparser.py
@@ -145,7 +145,7 @@ def handle_error(
         schema: Schema,
         error_status_code: typing.Union[int, None] = None,
         error_headers: typing.Union[typing.Mapping[str, str], None] = None,
-    ) -> typing.NoReturn:
+    ) -> "typing.NoReturn":
         """Handle ValidationErrors and return a JSON response of error messages
         to the client.
         """
@@ -163,7 +163,7 @@ def handle_error(
 
     def handle_invalid_json_error(
         self, error: json.JSONDecodeError, req: Request, *args, **kwargs
-    ) -> typing.NoReturn:
+    ) -> "typing.NoReturn":
         error_class = exception_map[400]
         messages = {"json": ["Invalid JSON body."]}
         raise error_class(


Test patch:
Repository: marshmallow-code/webargs

Issue:
Fix compatibility with Falcon 2.0
Tests are currently failing when Falcon 2.0.0 is installed.


Discussion:
I'm considering separating the falcon parser into a separate package. This isn't the first time breaking changes in Falcon have become a release blocker (https://github.com/marshmallow-code/webargs/issues/110). Perhaps we can keep the current webargs.falconparser compatible with 1.x and create a new webargs-falcon package for 2.0 and above.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
     "tornado>=4.5.2",
     "pyramid>=1.9.1",
     "webapp2>=3.0.0b1",
-    "falcon>=1.4.0",
+    "falcon>=1.4.0,<2.0",
     'aiohttp>=3.0.0; python_version >= "3.5"',
 ]
 EXTRAS_REQUIRE = {


Test patch:
Repository: marshmallow-code/webargs

Issue:
Schema factory only variable fail - can't pass list type
Looking at the [schema factory docs](https://webargs.readthedocs.io/en/latest/advanced.html#schema-factories), I'm interested in trying the
```
# Filter based on 'fields' query parameter
only = request.args.get("fields", None)
```
part.

However, when I try appending something like `?fields=some_field` to my HTTP request, I get the following error:
```
File "edited/marshmallow/schema.py", line 349, in __init__
    raise StringNotCollectionError('"only" should be a list of strings')
```

As far as I can see, webargs always passes the query string parameters as strings. I tried wrapping it in square brackets, but I think I'm barking up the wrong tree. Have I misunderstood something, or is this a bug?


Discussion:
It's possible the docs are incorrect. `only` does need to be a collection of strings, but `request.args.get` will return a string. Can you try using `request.args.getlist('fields')` instead?

Resolving patch:
diff --git a/examples/schema_example.py b/examples/schema_example.py
--- a/examples/schema_example.py
+++ b/examples/schema_example.py
@@ -89,9 +89,6 @@ class UserSchema(Schema):
     first_name = fields.Str()
     last_name = fields.Str()
 
-    class Meta:
-        strict = True
-
     @post_dump(pass_many=True)
     def wrap_with_envelope(self, data, many, **kwargs):
         return {"data": data}


Test patch:
Repository: marshmallow-code/webargs

Issue:
Importing ABC directly from collections module was removed in Python 3.9
Since the project is Python 3 only importing from collections.abc will resolve the issue. I will raise a PR.

https://github.com/marshmallow-code/webargs/blob/1b34470908cb54862b7aeb578f794ac3285cdf38/src/webargs/pyramidparser.py#L141


Discussion:

Resolving patch:
diff --git a/src/webargs/pyramidparser.py b/src/webargs/pyramidparser.py
--- a/src/webargs/pyramidparser.py
+++ b/src/webargs/pyramidparser.py
@@ -138,7 +138,7 @@ def use_args(
         location = location or self.location
         # Optimization: If argmap is passed as a dictionary, we only need
         # to generate a Schema once
-        if isinstance(argmap, collections.Mapping):
+        if isinstance(argmap, collections.abc.Mapping):
             argmap = core.dict2schema(argmap, self.schema_class)()
 
         def decorator(func):


Test patch:
Repository: marshmallow-code/webargs

Issue:
Fix simple typo: objec -> object
There is a small typo in src/webargs/flaskparser.py.
Should read `object` rather than `objec`.




Discussion:

Resolving patch:
diff --git a/src/webargs/flaskparser.py b/src/webargs/flaskparser.py
--- a/src/webargs/flaskparser.py
+++ b/src/webargs/flaskparser.py
@@ -114,7 +114,7 @@ def handle_error(self, error, req, schema, *, error_status_code, error_headers):
         )
 
     def get_default_request(self):
-        """Override to use Flask's thread-local request objec by default"""
+        """Override to use Flask's thread-local request object by default"""
         return flask.request
 
 


Test patch:
Repository: marshmallow-code/webargs

Issue:
Suggest including URL variable parameters in more examples
I'm totally new to Flask, Marshmallow, SQLAlchemy, webargs and this ecosystem. I was given a coding test and while trying to complete it, I had to use flaskparser together with an URL parameter. Not knowing how to configure them to be used together, I googled "flaskparser". The top 5 results are:

- https://webargs.readthedocs.io/en/latest/_modules/webargs/flaskparser.html
- https://webargs.readthedocs.io/en/latest/
- https://webargs.readthedocs.io/en/latest/api.html
- https://webargs.readthedocs.io/en/latest/advanced.html
- https://webargs.readthedocs.io/en/latest/quickstart.html

None of these include an example where an URL variable parameter and webargs are used together. I found the example that I need in [Framework Support](https://github.com/marshmallow-code/webargs/blob/dev/docs/framework_support.rst) (which does not appear on the first page of the Google results) as following:

```
from webargs import fields
from webargs.flaskparser import use_args


@app.route("/user/<int:uid>")
@use_args({"per_page": fields.Int()}, location="query")
def user_detail(args, uid):
    return ("The user page for user {uid}, showing {per_page} posts.").format(
        uid=uid, per_page=args["per_page"]
    )
```

Since the simpler use can can be inferred from the more complex use case, but not vice-versa, I would suggest to either include this code example in [flaskparser.py example](https://github.com/marshmallow-code/webargs/edit/dev/src/webargs/flaskparser.py), or somehow tweak the SEO for https://webargs.readthedocs.io/en/latest/framework_support.html so that it will appear on the first page of Google search results.


Discussion:

Resolving patch:
diff --git a/src/webargs/flaskparser.py b/src/webargs/flaskparser.py
--- a/src/webargs/flaskparser.py
+++ b/src/webargs/flaskparser.py
@@ -9,14 +9,16 @@
 
     app = Flask(__name__)
 
-    hello_args = {
-        'name': fields.Str(required=True)
+    user_detail_args = {
+        'per_page': fields.Int()
     }
 
-    @app.route('/')
-    @use_args(hello_args)
-    def index(args):
-        return 'Hello ' + args['name']
+    @app.route("/user/<int:uid>")
+    @use_args(user_detail_args)
+    def user_detail(args, uid):
+        return ("The user page for user {uid}, showing {per_page} posts.").format(
+            uid=uid, per_page=args["per_page"]
+        )
 """
 import flask
 from werkzeug.exceptions import HTTPException


Test patch:
Repository: marshmallow-code/webargs

Issue:
Add support for headers to DjangoParser
```
NotImplementedError: Header parsing not supported by DjangoParser
```


Discussion:
The decision not to support this was made 7 years ago (i.e. circa Django 1.5), and I think django didn't support this well.
I think we can add support today -- I'll try to find the time to do it and test properly.

For now, I think you could just go with the following snippet to get support
```python
from webargs.djangoparser import DjangoParser

class Parser(DjangoParser):
    def load_headers(self, req, schema):
        return req.META

djangoparser = Parser()
use_args = djangoparser.use_args
use_kwargs = djangoparser.use_kwarg
```
I just noticed that this was closed incorrectly.
I'd like to fix this in 7.0. Reopening and adding to the milestone.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 
 FRAMEWORKS = [
     "Flask>=0.12.2",
-    "Django>=1.11.16",
+    "Django>=2.2.0",
     "bottle>=0.12.13",
     "tornado>=4.5.2",
     "pyramid>=1.9.1",
diff --git a/src/webargs/djangoparser.py b/src/webargs/djangoparser.py
--- a/src/webargs/djangoparser.py
+++ b/src/webargs/djangoparser.py
@@ -59,9 +59,10 @@ def load_cookies(self, req, schema):
         return req.COOKIES
 
     def load_headers(self, req, schema):
-        raise NotImplementedError(
-            f"Header parsing not supported by {self.__class__.__name__}"
-        )
+        """Return headers from the request."""
+        # Django's HttpRequest.headers is a case-insensitive dict type, but it
+        # isn't a multidict, so this is not proxied
+        return req.headers
 
     def load_files(self, req, schema):
         """Return files from the request as a MultiDictProxy."""


Test patch:
diff --git a/tests/test_djangoparser.py b/tests/test_djangoparser.py
--- a/tests/test_djangoparser.py
+++ b/tests/test_djangoparser.py
@@ -14,10 +14,6 @@ def create_app(self):
     def test_use_args_with_validation(self):
         pass
 
-    @pytest.mark.skip(reason="headers location not supported by DjangoParser")
-    def test_parsing_headers(self, testapp):
-        pass
-
     def test_parsing_in_class_based_view(self, testapp):
         assert testapp.get("/echo_cbv?name=Fred").json == {"name": "Fred"}
         assert testapp.post_json("/echo_cbv", {"name": "Fred"}).json == {"name": "Fred"}
Repository: marshmallow-code/webargs

Issue:
webargs.core.Parser should describe default for unknown either as marshmallow.EXCLUDE or "exclude"
Current description says this:

> unknown (str) – A value to pass for unknown when calling the schema’s load method. Defaults to EXCLUDE for non-body locations and RAISE for request bodies. Pass None to use the schema’s setting instead.

`EXCLUDE` doesn't exist as a symbol in webargs, only in marshmallow and trying something like `"EXCLUDE"` fails and it takes time to figure this one out. Perhaps this description should reference either `marshmallow.EXCLUDE` or a marshmallow's value, such as `"exclude"`, to make it more clear.


Discussion:
This sounds to me like a reasonable documentation fix.

Let's go with `marshmallow.EXCLUDE` -- the fact that the constant is just a string is a detail of marshmallow, not something which is a clear and explicit part of marshmallow's API.

Resolving patch:
diff --git a/src/webargs/core.py b/src/webargs/core.py
--- a/src/webargs/core.py
+++ b/src/webargs/core.py
@@ -125,8 +125,8 @@ class Parser:
 
     :param str location: Default location to use for data
     :param str unknown: A default value to pass for ``unknown`` when calling the
-        schema's ``load`` method. Defaults to EXCLUDE for non-body
-        locations and RAISE for request bodies. Pass ``None`` to use the
+        schema's ``load`` method. Defaults to ``marshmallow.EXCLUDE`` for non-body
+        locations and ``marshmallow.RAISE`` for request bodies. Pass ``None`` to use the
         schema's setting instead.
     :param callable error_handler: Custom error handler function.
     """
@@ -385,9 +385,9 @@ def parse(
             default, that means one of ``('json', 'query', 'querystring',
             'form', 'headers', 'cookies', 'files', 'json_or_form')``.
         :param str unknown: A value to pass for ``unknown`` when calling the
-            schema's ``load`` method. Defaults to EXCLUDE for non-body
-            locations and RAISE for request bodies. Pass ``None`` to use the
-            schema's setting instead.
+            schema's ``load`` method. Defaults to ``marshmallow.EXCLUDE`` for non-body
+            locations and ``marshmallow.RAISE`` for request bodies. Pass ``None`` to use
+            the schema's setting instead.
         :param callable validate: Validation function or list of validation functions
             that receives the dictionary of parsed arguments. Validator either returns a
             boolean or raises a :exc:`ValidationError`.


Test patch:
Repository: marshmallow-code/webargs

Issue:
fix: schema_example.py status_code ignored
Just a small fix/enhancement for the examples in the webargs documentation.


Discussion:
Thanks for the contribution!

If the example is going to handle tuple return values, I think it should still call schema.dump on the result. Otherwise, the two branches are asymmetric in a potentially surprising way.
Hi ! Thank you for you answer !

I will adapt the code, and propose a modification

Resolving patch:
diff --git a/examples/schema_example.py b/examples/schema_example.py
--- a/examples/schema_example.py
+++ b/examples/schema_example.py
@@ -14,9 +14,9 @@
     $ http GET :5001/users/ limit==1
 """
 import functools
-from flask import Flask, request
 import random
 
+from flask import Flask, request
 from marshmallow import Schema, fields, post_dump
 from webargs.flaskparser import parser, use_kwargs
 
@@ -74,6 +74,11 @@ def wrapped(*args, **kwargs):
             # Function wrapped with use_args
             func_with_args = use_args_wrapper(func)
             ret = func_with_args(*args, **kwargs)
+
+            # support (json, status) tuples
+            if isinstance(ret, tuple) and len(ret) == 2 and isinstance(ret[1], int):
+                return schema.dump(ret[0], many=list_view), ret[1]
+
             return schema.dump(ret, many=list_view)
 
         return wrapped


Test patch:
Repository: safe-global/safe-config-service

Issue:
Add Safe App Provider information
The service should (optionally) include information about the provider of the application.

The provider information should have at least the following fields:

```json
{
  "name" : <string>,
  "url": <string>
}
```


Discussion:

Resolving patch:
diff --git a/src/safe_apps/admin.py b/src/safe_apps/admin.py
--- a/src/safe_apps/admin.py
+++ b/src/safe_apps/admin.py
@@ -1,5 +1,6 @@
 from django.contrib import admin
 
-from .models import SafeApp
+from .models import SafeApp, Provider
 
-admin.site.register(SafeApp)
+models = [SafeApp, Provider]
+admin.site.register(models)
diff --git a/src/safe_apps/migrations/0001_initial.py b/src/safe_apps/migrations/0001_initial.py
--- a/src/safe_apps/migrations/0001_initial.py
+++ b/src/safe_apps/migrations/0001_initial.py
@@ -1,7 +1,8 @@
-# Generated by Django 3.2 on 2021-04-28 13:39
+# Generated by Django 3.2 on 2021-04-29 08:22
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -12,6 +13,13 @@ class Migration(migrations.Migration):
     ]
 
     operations = [
+        migrations.CreateModel(
+            name='Provider',
+            fields=[
+                ('url', models.URLField(primary_key=True, serialize=False)),
+                ('name', models.CharField(max_length=200)),
+            ],
+        ),
         migrations.CreateModel(
             name='SafeApp',
             fields=[
@@ -20,6 +28,7 @@ class Migration(migrations.Migration):
                 ('icon_url', models.URLField()),
                 ('description', models.CharField(max_length=200)),
                 ('networks', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), size=None)),
+                ('provider', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='safe_apps.provider')),
             ],
         ),
     ]
diff --git a/src/safe_apps/models.py b/src/safe_apps/models.py
--- a/src/safe_apps/models.py
+++ b/src/safe_apps/models.py
@@ -2,9 +2,21 @@
 from django.db import models
 
 
+class Provider(models.Model):
+    url = models.URLField(primary_key=True)
+    name = models.CharField(max_length=200)
+
+    def __str__(self):
+        return f'{self.name} | {self.url}'
+
+
 class SafeApp(models.Model):
     url = models.URLField(primary_key=True)
     name = models.CharField(max_length=200)
     icon_url = models.URLField()
     description = models.CharField(max_length=200)
     networks = ArrayField(models.IntegerField())
+    provider = models.ForeignKey(Provider, null=True, on_delete=models.SET_NULL)
+
+    def __str__(self):
+        return f'{self.name} | {self.url} | networks={self.networks}'


Test patch:
Repository: safe-global/safe-config-service

Issue:
Improve admin page
- [x] Add custom Admin models with `list_display`, `display_filter` (for example, by network), `ordering` and `search_fields`: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/
- [x] Use admin decorator https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#the-register-decorator


Discussion:

Resolving patch:
diff --git a/src/safe_apps/admin.py b/src/safe_apps/admin.py
--- a/src/safe_apps/admin.py
+++ b/src/safe_apps/admin.py
@@ -2,5 +2,34 @@
 
 from .models import SafeApp, Provider
 
-models = [SafeApp, Provider]
-admin.site.register(models)
+
+class NetworksFilter(admin.SimpleListFilter):
+    title = 'Networks'
+    parameter_name = 'networks'
+
+    def lookups(self, request, model_admin):
+        values = SafeApp.objects.values_list('networks', flat=True)
+        # lookups requires a tuple to be returned – (value, verbose value)
+        networks = [(network, network) for networks in values for network in networks]
+        networks = sorted(set(networks))
+        return networks
+
+    def queryset(self, request, queryset):
+        if value := self.value():
+            queryset = queryset.filter(networks__contains=[value])
+        return queryset
+
+
+@admin.register(SafeApp)
+class SafeAppAdmin(admin.ModelAdmin):
+    list_display = ('name', 'url', 'networks')
+    list_filter = (NetworksFilter,)
+    search_fields = ('name', 'url')
+    ordering = ('name',)
+
+
+@admin.register(Provider)
+class ProviderAdmin(admin.ModelAdmin):
+    list_display = ('name', 'url')
+    search_fields = ('name',)
+    ordering = ('name',)


Test patch:
Repository: safe-global/safe-config-service

Issue:
Set port numbers in docker compose via environment variables
To provide more flexibility when setting up the ports for a given environment, we should not use static ports in `docker-compose`. Instead those ports should be extracted to the `.env` file.


Discussion:

Resolving patch:
diff --git a/src/config/gunicorn.py b/src/config/gunicorn.py
--- a/src/config/gunicorn.py
+++ b/src/config/gunicorn.py
@@ -2,7 +2,7 @@
 import os
 from distutils.util import strtobool
 
-bind = f"0.0.0.0:{os.getenv('PORT', '8000')}"
+bind = f"0.0.0.0:{os.getenv('GUNICORN_BIND_PORT', '8000')}"
 accesslog = "-"
 
 workers = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2))


Test patch: