We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
0077_move_remote_url_credentials.py fails on Remotes that have @ in path, not netloc
**Version**
3.18.10

**Describe the bug**
Migration 0077 fails when you have a remote that has an @ somewhere in the path

```
  Applying core.0077_move_remote_url_credentials...Traceback (most recent call last):
  File "/usr/bin/pulpcore-manager", line 33, in <module>
    sys.exit(load_entry_point('pulpcore==3.18.10', 'console_scripts', 'pulpcore-manager')())
  File "/usr/lib/python3.9/site-packages/pulpcore/app/manage.py", line 11, in manage
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/usr/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/lib/python3.9/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/lib/python3.9/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/usr/lib/python3.9/site-packages/pulpcore/app/migrations/0077_move_remote_url_credentials.py", line 19, in move_remote_url_credentials
    _, url_split = url.netloc.rsplit("@", maxsplit=1)
ValueError: not enough values to unpack (expected 2, got 1)
```

**To Reproduce**
Steps to reproduce the behavior:
* Have a remote `https://download.copr.fedorainfracloud.org/results/@caddy/caddy/epel-8-x86_64/`
* Try to migrate 0077

**Expected behavior**
migration aplies

**Additional context**
https://community.theforeman.org/t/foreman-3-3-katello-4-5-upgrade-failed-pulpcore-manager-migrate-noinput/31088


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pulpcore/app/migrations/0077_move_remote_url_credentials.py`
Content:
```
1 # Generated by Django 3.2.6 on 2021-09-29 14:00
2 
3 from urllib.parse import urlparse, urlunparse
4 
5 from django.db import migrations
6 
7 
8 def move_remote_url_credentials(apps, schema_editor):
9     Remote = apps.get_model("core", "Remote")
10 
11     for remote in Remote.objects.filter(url__contains="@").iterator():
12         url = urlparse(remote.url)
13 
14         if not remote.username:
15             remote.username = url.username
16         if not remote.password:
17             remote.password = url.password
18 
19         _, url_split = url.netloc.rsplit("@", maxsplit=1)
20         remote.url = urlunparse(url._replace(netloc=url_split))
21         remote.save()
22 
23 
24 class Migration(migrations.Migration):
25 
26     dependencies = [
27         ('core', '0076_remove_reserved_resource'),
28     ]
29 
30     operations = [
31         migrations.RunPython(
32             code=move_remote_url_credentials,
33             reverse_code=migrations.RunPython.noop,
34             elidable=True,
35         )
36     ]
37
```
--- 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/pulpcore/app/migrations/0077_move_remote_url_credentials.py b/pulpcore/app/migrations/0077_move_remote_url_credentials.py
--- a/pulpcore/app/migrations/0077_move_remote_url_credentials.py
+++ b/pulpcore/app/migrations/0077_move_remote_url_credentials.py
@@ -11,6 +11,11 @@
     for remote in Remote.objects.filter(url__contains="@").iterator():
         url = urlparse(remote.url)
 
+        if '@' not in url.netloc:
+            # URLs can have an @ in other places than the netloc,
+            # but those do not indicate credentials
+            continue
+
         if not remote.username:
             remote.username = url.username
         if not remote.password:

{"golden_diff": "diff --git a/pulpcore/app/migrations/0077_move_remote_url_credentials.py b/pulpcore/app/migrations/0077_move_remote_url_credentials.py\n--- a/pulpcore/app/migrations/0077_move_remote_url_credentials.py\n+++ b/pulpcore/app/migrations/0077_move_remote_url_credentials.py\n@@ -11,6 +11,11 @@\n     for remote in Remote.objects.filter(url__contains=\"@\").iterator():\n         url = urlparse(remote.url)\n \n+        if '@' not in url.netloc:\n+            # URLs can have an @ in other places than the netloc,\n+            # but those do not indicate credentials\n+            continue\n+\n         if not remote.username:\n             remote.username = url.username\n         if not remote.password:\n", "issue": "0077_move_remote_url_credentials.py fails on Remotes that have @ in path, not netloc\n**Version**\r\n3.18.10\r\n\r\n**Describe the bug**\r\nMigration 0077 fails when you have a remote that has an @ somewhere in the path\r\n\r\n```\r\n  Applying core.0077_move_remote_url_credentials...Traceback (most recent call last):\r\n  File \"/usr/bin/pulpcore-manager\", line 33, in <module>\r\n    sys.exit(load_entry_point('pulpcore==3.18.10', 'console_scripts', 'pulpcore-manager')())\r\n  File \"/usr/lib/python3.9/site-packages/pulpcore/app/manage.py\", line 11, in manage\r\n    execute_from_command_line(sys.argv)\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/__init__.py\", line 419, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/__init__.py\", line 413, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/base.py\", line 354, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/base.py\", line 398, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/base.py\", line 89, in wrapped\r\n    res = handle_func(*args, **kwargs)\r\n  File \"/usr/lib/python3.9/site-packages/django/core/management/commands/migrate.py\", line 244, in handle\r\n    post_migrate_state = executor.migrate(\r\n  File \"/usr/lib/python3.9/site-packages/django/db/migrations/executor.py\", line 117, in migrate\r\n    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)\r\n  File \"/usr/lib/python3.9/site-packages/django/db/migrations/executor.py\", line 147, in _migrate_all_forwards\r\n    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)\r\n  File \"/usr/lib/python3.9/site-packages/django/db/migrations/executor.py\", line 227, in apply_migration\r\n    state = migration.apply(state, schema_editor)\r\n  File \"/usr/lib/python3.9/site-packages/django/db/migrations/migration.py\", line 126, in apply\r\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\r\n  File \"/usr/lib/python3.9/site-packages/django/db/migrations/operations/special.py\", line 190, in database_forwards\r\n    self.code(from_state.apps, schema_editor)\r\n  File \"/usr/lib/python3.9/site-packages/pulpcore/app/migrations/0077_move_remote_url_credentials.py\", line 19, in move_remote_url_credentials\r\n    _, url_split = url.netloc.rsplit(\"@\", maxsplit=1)\r\nValueError: not enough values to unpack (expected 2, got 1)\r\n```\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n* Have a remote `https://download.copr.fedorainfracloud.org/results/@caddy/caddy/epel-8-x86_64/`\r\n* Try to migrate 0077\r\n\r\n**Expected behavior**\r\nmigration aplies\r\n\r\n**Additional context**\r\nhttps://community.theforeman.org/t/foreman-3-3-katello-4-5-upgrade-failed-pulpcore-manager-migrate-noinput/31088\r\n\n", "before_files": [{"content": "# Generated by Django 3.2.6 on 2021-09-29 14:00\n\nfrom urllib.parse import urlparse, urlunparse\n\nfrom django.db import migrations\n\n\ndef move_remote_url_credentials(apps, schema_editor):\n    Remote = apps.get_model(\"core\", \"Remote\")\n\n    for remote in Remote.objects.filter(url__contains=\"@\").iterator():\n        url = urlparse(remote.url)\n\n        if not remote.username:\n            remote.username = url.username\n        if not remote.password:\n            remote.password = url.password\n\n        _, url_split = url.netloc.rsplit(\"@\", maxsplit=1)\n        remote.url = urlunparse(url._replace(netloc=url_split))\n        remote.save()\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('core', '0076_remove_reserved_resource'),\n    ]\n\n    operations = [\n        migrations.RunPython(\n            code=move_remote_url_credentials,\n            reverse_code=migrations.RunPython.noop,\n            elidable=True,\n        )\n    ]\n", "path": "pulpcore/app/migrations/0077_move_remote_url_credentials.py"}], "after_files": [{"content": "# Generated by Django 3.2.6 on 2021-09-29 14:00\n\nfrom urllib.parse import urlparse, urlunparse\n\nfrom django.db import migrations\n\n\ndef move_remote_url_credentials(apps, schema_editor):\n    Remote = apps.get_model(\"core\", \"Remote\")\n\n    for remote in Remote.objects.filter(url__contains=\"@\").iterator():\n        url = urlparse(remote.url)\n\n        if '@' not in url.netloc:\n            # URLs can have an @ in other places than the netloc,\n            # but those do not indicate credentials\n            continue\n\n        if not remote.username:\n            remote.username = url.username\n        if not remote.password:\n            remote.password = url.password\n\n        _, url_split = url.netloc.rsplit(\"@\", maxsplit=1)\n        remote.url = urlunparse(url._replace(netloc=url_split))\n        remote.save()\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('core', '0076_remove_reserved_resource'),\n    ]\n\n    operations = [\n        migrations.RunPython(\n            code=move_remote_url_credentials,\n            reverse_code=migrations.RunPython.noop,\n            elidable=True,\n        )\n    ]\n", "path": "pulpcore/app/migrations/0077_move_remote_url_credentials.py"}]}