We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
New user creation results in TypeError
If one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.

![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)

New user creation results in TypeError
If one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.

![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cms/forms/users/user_profile_form.py`
Content:
```
1 """
2 Form for creating a user object
3 """
4 import logging
5 
6 from django import forms
7 
8 from ...models import UserProfile
9 
10 
11 logger = logging.getLogger(__name__)
12 
13 
14 class UserProfileForm(forms.ModelForm):
15 
16     class Meta:
17         model = UserProfile
18         fields = [
19             'regions',
20             'organization'
21         ]
22 
23     # pylint: disable=arguments-differ
24     def save(self, *args, **kwargs):
25 
26         logger.info(
27             'UserProfileForm saved with args %s and kwargs %s',
28             args,
29             kwargs
30         )
31 
32         # pop kwarg to make sure the super class does not get this param
33         user = kwargs.pop('user', None)
34 
35         if not self.instance.id:
36             # don't commit saving of ModelForm, because required user field is still missing
37             kwargs['commit'] = False
38 
39         # save ModelForm
40         user_profile = super(UserProfileForm, self).save(*args, **kwargs)
41 
42         if not self.instance.id:
43             user_profile.user = user
44             user_profile.save()
45             # check if called from UserProfileForm or RegionUserProfileForm
46             if 'regions' in self.cleaned_data:
47                 # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly
48                 user_profile.regions = self.cleaned_data['regions']
49                 user_profile.save()
50 
51         return user_profile
52
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cms/forms/users/user_profile_form.py b/src/cms/forms/users/user_profile_form.py
--- a/src/cms/forms/users/user_profile_form.py
+++ b/src/cms/forms/users/user_profile_form.py
@@ -45,7 +45,6 @@
             # check if called from UserProfileForm or RegionUserProfileForm
             if 'regions' in self.cleaned_data:
                 # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly
-                user_profile.regions = self.cleaned_data['regions']
-                user_profile.save()
+                user_profile.regions.set(self.cleaned_data['regions'])
 
         return user_profile

{"golden_diff": "diff --git a/src/cms/forms/users/user_profile_form.py b/src/cms/forms/users/user_profile_form.py\n--- a/src/cms/forms/users/user_profile_form.py\n+++ b/src/cms/forms/users/user_profile_form.py\n@@ -45,7 +45,6 @@\n             # check if called from UserProfileForm or RegionUserProfileForm\n             if 'regions' in self.cleaned_data:\n                 # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly\n-                user_profile.regions = self.cleaned_data['regions']\n-                user_profile.save()\n+                user_profile.regions.set(self.cleaned_data['regions'])\n \n         return user_profile\n", "issue": "New user creation results in TypeError\nIf one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.\r\n\r\n![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)\r\n\nNew user creation results in TypeError\nIf one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.\r\n\r\n![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)\r\n\n", "before_files": [{"content": "\"\"\"\nForm for creating a user object\n\"\"\"\nimport logging\n\nfrom django import forms\n\nfrom ...models import UserProfile\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass UserProfileForm(forms.ModelForm):\n\n    class Meta:\n        model = UserProfile\n        fields = [\n            'regions',\n            'organization'\n        ]\n\n    # pylint: disable=arguments-differ\n    def save(self, *args, **kwargs):\n\n        logger.info(\n            'UserProfileForm saved with args %s and kwargs %s',\n            args,\n            kwargs\n        )\n\n        # pop kwarg to make sure the super class does not get this param\n        user = kwargs.pop('user', None)\n\n        if not self.instance.id:\n            # don't commit saving of ModelForm, because required user field is still missing\n            kwargs['commit'] = False\n\n        # save ModelForm\n        user_profile = super(UserProfileForm, self).save(*args, **kwargs)\n\n        if not self.instance.id:\n            user_profile.user = user\n            user_profile.save()\n            # check if called from UserProfileForm or RegionUserProfileForm\n            if 'regions' in self.cleaned_data:\n                # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly\n                user_profile.regions = self.cleaned_data['regions']\n                user_profile.save()\n\n        return user_profile\n", "path": "src/cms/forms/users/user_profile_form.py"}], "after_files": [{"content": "\"\"\"\nForm for creating a user object\n\"\"\"\nimport logging\n\nfrom django import forms\n\nfrom ...models import UserProfile\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass UserProfileForm(forms.ModelForm):\n\n    class Meta:\n        model = UserProfile\n        fields = [\n            'regions',\n            'organization'\n        ]\n\n    # pylint: disable=arguments-differ\n    def save(self, *args, **kwargs):\n\n        logger.info(\n            'UserProfileForm saved with args %s and kwargs %s',\n            args,\n            kwargs\n        )\n\n        # pop kwarg to make sure the super class does not get this param\n        user = kwargs.pop('user', None)\n\n        if not self.instance.id:\n            # don't commit saving of ModelForm, because required user field is still missing\n            kwargs['commit'] = False\n\n        # save ModelForm\n        user_profile = super(UserProfileForm, self).save(*args, **kwargs)\n\n        if not self.instance.id:\n            user_profile.user = user\n            user_profile.save()\n            # check if called from UserProfileForm or RegionUserProfileForm\n            if 'regions' in self.cleaned_data:\n                # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly\n                user_profile.regions.set(self.cleaned_data['regions'])\n\n        return user_profile\n", "path": "src/cms/forms/users/user_profile_form.py"}]}