prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Users can create the same address multiple times
  ### Steps to reproduce the problem
  1. Start checkout
  1. Set a shipping address A
  1. Set a billing address B
  1. Place the order
  1. Go to your account details
  1. Edit the address B to have the same information than A
  1. Checkout with A or B (or re-create it through a new address input?)
  1. Place the order
  1. The order should have failed because the same address exist two times: `get() returned more than one object`
  
  
  ### What I expected to happen
  Have an error when updating the address, saying I already have that address.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `saleor/account/utils.py`
  Content:
  ```
  1 import os
  2 import os.path
  3 import random
  4 
  5 from django.conf import settings
  6 from django.core.files import File
  7 
  8 from ..checkout import AddressType
  9 
  10 AVATARS_PATH = os.path.join(
  11     settings.PROJECT_ROOT, "saleor", "static", "images", "avatars"
  12 )
  13 
  14 
  15 def store_user_address(user, address, address_type):
  16     """Add address to user address book and set as default one."""
  17     address, _ = user.addresses.get_or_create(**address.as_data())
  18 
  19     if address_type == AddressType.BILLING:
  20         if not user.default_billing_address:
  21             set_user_default_billing_address(user, address)
  22     elif address_type == AddressType.SHIPPING:
  23         if not user.default_shipping_address:
  24             set_user_default_shipping_address(user, address)
  25 
  26 
  27 def set_user_default_billing_address(user, address):
  28     user.default_billing_address = address
  29     user.save(update_fields=["default_billing_address"])
  30 
  31 
  32 def set_user_default_shipping_address(user, address):
  33     user.default_shipping_address = address
  34     user.save(update_fields=["default_shipping_address"])
  35 
  36 
  37 def change_user_default_address(user, address, address_type):
  38     if address_type == AddressType.BILLING:
  39         if user.default_billing_address:
  40             user.addresses.add(user.default_billing_address)
  41         set_user_default_billing_address(user, address)
  42     elif address_type == AddressType.SHIPPING:
  43         if user.default_shipping_address:
  44             user.addresses.add(user.default_shipping_address)
  45         set_user_default_shipping_address(user, address)
  46 
  47 
  48 def get_user_first_name(user):
  49     """Return a user's first name from their default belling address.
  50 
  51     Return nothing if none where found.
  52     """
  53     if user.first_name:
  54         return user.first_name
  55     if user.default_billing_address:
  56         return user.default_billing_address.first_name
  57     return None
  58 
  59 
  60 def get_user_last_name(user):
  61     """Return a user's last name from their default belling address.
  62 
  63     Return nothing if none where found.
  64     """
  65     if user.last_name:
  66         return user.last_name
  67     if user.default_billing_address:
  68         return user.default_billing_address.last_name
  69     return None
  70 
  71 
  72 def get_random_avatar():
  73     """Return random avatar picked from a pool of static avatars."""
  74     avatar_name = random.choice(os.listdir(AVATARS_PATH))
  75     avatar_path = os.path.join(AVATARS_PATH, avatar_name)
  76     return File(open(avatar_path, "rb"), name=avatar_name)
  77
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/saleor/account/utils.py b/saleor/account/utils.py
  --- a/saleor/account/utils.py
  +++ b/saleor/account/utils.py
  @@ -14,7 +14,11 @@
   
   def store_user_address(user, address, address_type):
       """Add address to user address book and set as default one."""
  -    address, _ = user.addresses.get_or_create(**address.as_data())
  +    address_data = address.as_data()
  +
  +    address = user.addresses.filter(**address_data).first()
  +    if address is None:
  +        address = user.addresses.create(**address_data)
   
       if address_type == AddressType.BILLING:
           if not user.default_billing_address:
  
verification_info: {"golden_diff": "diff --git a/saleor/account/utils.py b/saleor/account/utils.py\n--- a/saleor/account/utils.py\n+++ b/saleor/account/utils.py\n@@ -14,7 +14,11 @@\n \n def store_user_address(user, address, address_type):\n     \"\"\"Add address to user address book and set as default one.\"\"\"\n-    address, _ = user.addresses.get_or_create(**address.as_data())\n+    address_data = address.as_data()\n+\n+    address = user.addresses.filter(**address_data).first()\n+    if address is None:\n+        address = user.addresses.create(**address_data)\n \n     if address_type == AddressType.BILLING:\n         if not user.default_billing_address:\n", "issue": "Users can create the same address multiple times\n### Steps to reproduce the problem\r\n1. Start checkout\r\n1. Set a shipping address A\r\n1. Set a billing address B\r\n1. Place the order\r\n1. Go to your account details\r\n1. Edit the address B to have the same information than A\r\n1. Checkout with A or B (or re-create it through a new address input?)\r\n1. Place the order\r\n1. The order should have failed because the same address exist two times: `get() returned more than one object`\r\n\r\n\r\n### What I expected to happen\r\nHave an error when updating the address, saying I already have that address.\r\n\n", "before_files": [{"content": "import os\nimport os.path\nimport random\n\nfrom django.conf import settings\nfrom django.core.files import File\n\nfrom ..checkout import AddressType\n\nAVATARS_PATH = os.path.join(\n    settings.PROJECT_ROOT, \"saleor\", \"static\", \"images\", \"avatars\"\n)\n\n\ndef store_user_address(user, address, address_type):\n    \"\"\"Add address to user address book and set as default one.\"\"\"\n    address, _ = user.addresses.get_or_create(**address.as_data())\n\n    if address_type == AddressType.BILLING:\n        if not user.default_billing_address:\n            set_user_default_billing_address(user, address)\n    elif address_type == AddressType.SHIPPING:\n        if not user.default_shipping_address:\n            set_user_default_shipping_address(user, address)\n\n\ndef set_user_default_billing_address(user, address):\n    user.default_billing_address = address\n    user.save(update_fields=[\"default_billing_address\"])\n\n\ndef set_user_default_shipping_address(user, address):\n    user.default_shipping_address = address\n    user.save(update_fields=[\"default_shipping_address\"])\n\n\ndef change_user_default_address(user, address, address_type):\n    if address_type == AddressType.BILLING:\n        if user.default_billing_address:\n            user.addresses.add(user.default_billing_address)\n        set_user_default_billing_address(user, address)\n    elif address_type == AddressType.SHIPPING:\n        if user.default_shipping_address:\n            user.addresses.add(user.default_shipping_address)\n        set_user_default_shipping_address(user, address)\n\n\ndef get_user_first_name(user):\n    \"\"\"Return a user's first name from their default belling address.\n\n    Return nothing if none where found.\n    \"\"\"\n    if user.first_name:\n        return user.first_name\n    if user.default_billing_address:\n        return user.default_billing_address.first_name\n    return None\n\n\ndef get_user_last_name(user):\n    \"\"\"Return a user's last name from their default belling address.\n\n    Return nothing if none where found.\n    \"\"\"\n    if user.last_name:\n        return user.last_name\n    if user.default_billing_address:\n        return user.default_billing_address.last_name\n    return None\n\n\ndef get_random_avatar():\n    \"\"\"Return random avatar picked from a pool of static avatars.\"\"\"\n    avatar_name = random.choice(os.listdir(AVATARS_PATH))\n    avatar_path = os.path.join(AVATARS_PATH, avatar_name)\n    return File(open(avatar_path, \"rb\"), name=avatar_name)\n", "path": "saleor/account/utils.py"}], "after_files": [{"content": "import os\nimport os.path\nimport random\n\nfrom django.conf import settings\nfrom django.core.files import File\n\nfrom ..checkout import AddressType\n\nAVATARS_PATH = os.path.join(\n    settings.PROJECT_ROOT, \"saleor\", \"static\", \"images\", \"avatars\"\n)\n\n\ndef store_user_address(user, address, address_type):\n    \"\"\"Add address to user address book and set as default one.\"\"\"\n    address_data = address.as_data()\n\n    address = user.addresses.filter(**address_data).first()\n    if address is None:\n        address = user.addresses.create(**address_data)\n\n    if address_type == AddressType.BILLING:\n        if not user.default_billing_address:\n            set_user_default_billing_address(user, address)\n    elif address_type == AddressType.SHIPPING:\n        if not user.default_shipping_address:\n            set_user_default_shipping_address(user, address)\n\n\ndef set_user_default_billing_address(user, address):\n    user.default_billing_address = address\n    user.save(update_fields=[\"default_billing_address\"])\n\n\ndef set_user_default_shipping_address(user, address):\n    user.default_shipping_address = address\n    user.save(update_fields=[\"default_shipping_address\"])\n\n\ndef change_user_default_address(user, address, address_type):\n    if address_type == AddressType.BILLING:\n        if user.default_billing_address:\n            user.addresses.add(user.default_billing_address)\n        set_user_default_billing_address(user, address)\n    elif address_type == AddressType.SHIPPING:\n        if user.default_shipping_address:\n            user.addresses.add(user.default_shipping_address)\n        set_user_default_shipping_address(user, address)\n\n\ndef get_user_first_name(user):\n    \"\"\"Return a user's first name from their default belling address.\n\n    Return nothing if none where found.\n    \"\"\"\n    if user.first_name:\n        return user.first_name\n    if user.default_billing_address:\n        return user.default_billing_address.first_name\n    return None\n\n\ndef get_user_last_name(user):\n    \"\"\"Return a user's last name from their default belling address.\n\n    Return nothing if none where found.\n    \"\"\"\n    if user.last_name:\n        return user.last_name\n    if user.default_billing_address:\n        return user.default_billing_address.last_name\n    return None\n\n\ndef get_random_avatar():\n    \"\"\"Return random avatar picked from a pool of static avatars.\"\"\"\n    avatar_name = random.choice(os.listdir(AVATARS_PATH))\n    avatar_path = os.path.join(AVATARS_PATH, avatar_name)\n    return File(open(avatar_path, \"rb\"), name=avatar_name)\n", "path": "saleor/account/utils.py"}]}