prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  management: `rename_stream` management command does not work
  `rename_stream` uses the `do_rename_stream` function to rename the stream. However, it accesses a non-existent attribute when calling it.
  
  ```
  do_rename_stream(stream, new_name, self.user_profile)  # self.user_profile does not exist
  ```
  
  To replicate this, run:
  ```
  python manage.py rename_stream Denmark bar -r zulip
  ```
  and you should see:
  ```
  AttributeError: 'Command' object has no attribute 'user_profile'
  ```
  You might want to look at `zerver/management/commands/rename_stream.py` and `zerver/actions/streams.py`.
  
  The fix should refactor `do_rename_stream` to accept `user_profile: Optional[UserProfile]` with the `None` default, and correctly handle what should happen for the notification message that might be sent when the stream is renamed (which currently mentions the name of the acting user that renames it).
  
  </issue>
  <code>
  [start of zerver/management/commands/rename_stream.py]
  1 from argparse import ArgumentParser
  2 from typing import Any
  3 
  4 from zerver.actions.streams import do_rename_stream
  5 from zerver.lib.management import ZulipBaseCommand
  6 from zerver.models import get_stream
  7 
  8 
  9 class Command(ZulipBaseCommand):
  10     help = """Change the stream name for a realm."""
  11 
  12     def add_arguments(self, parser: ArgumentParser) -> None:
  13         parser.add_argument("old_name", metavar="<old name>", help="name of stream to be renamed")
  14         parser.add_argument(
  15             "new_name", metavar="<new name>", help="new name to rename the stream to"
  16         )
  17         self.add_realm_args(parser, required=True)
  18 
  19     def handle(self, *args: Any, **options: str) -> None:
  20         realm = self.get_realm(options)
  21         assert realm is not None  # Should be ensured by parser
  22         old_name = options["old_name"]
  23         new_name = options["new_name"]
  24 
  25         stream = get_stream(old_name, realm)
  26         do_rename_stream(stream, new_name, self.user_profile)
  27
  [end of zerver/management/commands/rename_stream.py]
  [start of zilencer/management/commands/migrate_stream_notifications.py]
  1 from typing import Any
  2 
  3 from django.core.management.base import BaseCommand
  4 
  5 from zerver.models import Subscription
  6 
  7 
  8 class Command(BaseCommand):
  9     help = """One-off script to migration users' stream notification settings."""
  10 
  11     def handle(self, *args: Any, **options: Any) -> None:
  12         for subscription in Subscription.objects.all():
  13             subscription.desktop_notifications = subscription.notifications
  14             subscription.audible_notifications = subscription.notifications
  15             subscription.save(update_fields=["desktop_notifications", "audible_notifications"])
  16
  [end of zilencer/management/commands/migrate_stream_notifications.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/zerver/management/commands/rename_stream.py b/zerver/management/commands/rename_stream.py
  deleted file mode 100644
  --- a/zerver/management/commands/rename_stream.py
  +++ /dev/null
  @@ -1,26 +0,0 @@
  -from argparse import ArgumentParser
  -from typing import Any
  -
  -from zerver.actions.streams import do_rename_stream
  -from zerver.lib.management import ZulipBaseCommand
  -from zerver.models import get_stream
  -
  -
  -class Command(ZulipBaseCommand):
  -    help = """Change the stream name for a realm."""
  -
  -    def add_arguments(self, parser: ArgumentParser) -> None:
  -        parser.add_argument("old_name", metavar="<old name>", help="name of stream to be renamed")
  -        parser.add_argument(
  -            "new_name", metavar="<new name>", help="new name to rename the stream to"
  -        )
  -        self.add_realm_args(parser, required=True)
  -
  -    def handle(self, *args: Any, **options: str) -> None:
  -        realm = self.get_realm(options)
  -        assert realm is not None  # Should be ensured by parser
  -        old_name = options["old_name"]
  -        new_name = options["new_name"]
  -
  -        stream = get_stream(old_name, realm)
  -        do_rename_stream(stream, new_name, self.user_profile)
  diff --git a/zilencer/management/commands/migrate_stream_notifications.py b/zilencer/management/commands/migrate_stream_notifications.py
  deleted file mode 100644
  --- a/zilencer/management/commands/migrate_stream_notifications.py
  +++ /dev/null
  @@ -1,15 +0,0 @@
  -from typing import Any
  -
  -from django.core.management.base import BaseCommand
  -
  -from zerver.models import Subscription
  -
  -
  -class Command(BaseCommand):
  -    help = """One-off script to migration users' stream notification settings."""
  -
  -    def handle(self, *args: Any, **options: Any) -> None:
  -        for subscription in Subscription.objects.all():
  -            subscription.desktop_notifications = subscription.notifications
  -            subscription.audible_notifications = subscription.notifications
  -            subscription.save(update_fields=["desktop_notifications", "audible_notifications"])
  
verification_info: {"golden_diff": "diff --git a/zerver/management/commands/rename_stream.py b/zerver/management/commands/rename_stream.py\ndeleted file mode 100644\n--- a/zerver/management/commands/rename_stream.py\n+++ /dev/null\n@@ -1,26 +0,0 @@\n-from argparse import ArgumentParser\n-from typing import Any\n-\n-from zerver.actions.streams import do_rename_stream\n-from zerver.lib.management import ZulipBaseCommand\n-from zerver.models import get_stream\n-\n-\n-class Command(ZulipBaseCommand):\n-    help = \"\"\"Change the stream name for a realm.\"\"\"\n-\n-    def add_arguments(self, parser: ArgumentParser) -> None:\n-        parser.add_argument(\"old_name\", metavar=\"<old name>\", help=\"name of stream to be renamed\")\n-        parser.add_argument(\n-            \"new_name\", metavar=\"<new name>\", help=\"new name to rename the stream to\"\n-        )\n-        self.add_realm_args(parser, required=True)\n-\n-    def handle(self, *args: Any, **options: str) -> None:\n-        realm = self.get_realm(options)\n-        assert realm is not None  # Should be ensured by parser\n-        old_name = options[\"old_name\"]\n-        new_name = options[\"new_name\"]\n-\n-        stream = get_stream(old_name, realm)\n-        do_rename_stream(stream, new_name, self.user_profile)\ndiff --git a/zilencer/management/commands/migrate_stream_notifications.py b/zilencer/management/commands/migrate_stream_notifications.py\ndeleted file mode 100644\n--- a/zilencer/management/commands/migrate_stream_notifications.py\n+++ /dev/null\n@@ -1,15 +0,0 @@\n-from typing import Any\n-\n-from django.core.management.base import BaseCommand\n-\n-from zerver.models import Subscription\n-\n-\n-class Command(BaseCommand):\n-    help = \"\"\"One-off script to migration users' stream notification settings.\"\"\"\n-\n-    def handle(self, *args: Any, **options: Any) -> None:\n-        for subscription in Subscription.objects.all():\n-            subscription.desktop_notifications = subscription.notifications\n-            subscription.audible_notifications = subscription.notifications\n-            subscription.save(update_fields=[\"desktop_notifications\", \"audible_notifications\"])\n", "issue": "management: `rename_stream` management command does not work\n`rename_stream` uses the `do_rename_stream` function to rename the stream. However, it accesses a non-existent attribute when calling it.\r\n\r\n```\r\ndo_rename_stream(stream, new_name, self.user_profile)  # self.user_profile does not exist\r\n```\r\n\r\nTo replicate this, run:\r\n```\r\npython manage.py rename_stream Denmark bar -r zulip\r\n```\r\nand you should see:\r\n```\r\nAttributeError: 'Command' object has no attribute 'user_profile'\r\n```\r\nYou might want to look at `zerver/management/commands/rename_stream.py` and `zerver/actions/streams.py`.\r\n\r\nThe fix should refactor `do_rename_stream` to accept `user_profile: Optional[UserProfile]` with the `None` default, and correctly handle what should happen for the notification message that might be sent when the stream is renamed (which currently mentions the name of the acting user that renames it).\n", "before_files": [{"content": "from argparse import ArgumentParser\nfrom typing import Any\n\nfrom zerver.actions.streams import do_rename_stream\nfrom zerver.lib.management import ZulipBaseCommand\nfrom zerver.models import get_stream\n\n\nclass Command(ZulipBaseCommand):\n    help = \"\"\"Change the stream name for a realm.\"\"\"\n\n    def add_arguments(self, parser: ArgumentParser) -> None:\n        parser.add_argument(\"old_name\", metavar=\"<old name>\", help=\"name of stream to be renamed\")\n        parser.add_argument(\n            \"new_name\", metavar=\"<new name>\", help=\"new name to rename the stream to\"\n        )\n        self.add_realm_args(parser, required=True)\n\n    def handle(self, *args: Any, **options: str) -> None:\n        realm = self.get_realm(options)\n        assert realm is not None  # Should be ensured by parser\n        old_name = options[\"old_name\"]\n        new_name = options[\"new_name\"]\n\n        stream = get_stream(old_name, realm)\n        do_rename_stream(stream, new_name, self.user_profile)\n", "path": "zerver/management/commands/rename_stream.py"}, {"content": "from typing import Any\n\nfrom django.core.management.base import BaseCommand\n\nfrom zerver.models import Subscription\n\n\nclass Command(BaseCommand):\n    help = \"\"\"One-off script to migration users' stream notification settings.\"\"\"\n\n    def handle(self, *args: Any, **options: Any) -> None:\n        for subscription in Subscription.objects.all():\n            subscription.desktop_notifications = subscription.notifications\n            subscription.audible_notifications = subscription.notifications\n            subscription.save(update_fields=[\"desktop_notifications\", \"audible_notifications\"])\n", "path": "zilencer/management/commands/migrate_stream_notifications.py"}]}