prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Login fails at GET /api/v3/flows/executor/default-authentication-flow/ 
  **Describe the bug**
  Authentication fails.  I've tried my own auth flow, which includes a passwordless option.  This log is from switching back to the default auth flow.
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Enter Username
  2. Enter Password
  3. Press Enter
  4. See error
  
  **Expected behavior**
  This stage would normally be to select the authenticator to use.  (Key or TOTP, in my case)
  
  **Screenshots**
  If applicable, add screenshots to help explain your problem.
  
  **Logs**
  <details>
      <summary>Stacktrace from authentik</summary>
  
  ```
  Traceback (most recent call last):
    File "/authentik/flows/views/executor.py", line 287, in get
      stage_response = self.current_stage_view.dispatch(request)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
      return handler(request, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/authentik/stages/authenticator_validate/stage.py", line 222, in get
      challenges = self.get_device_challenges()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/authentik/stages/authenticator_validate/stage.py", line 157, in get_device_challenges
      user_devices = list(devices_for_user(self.get_pending_user()))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/authentik/stages/authenticator/__init__.py", line 93, in devices_for_user
      yield from device_set
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py", line 398, in __iter__
      self._fetch_all()
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1881, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py", line 91, in __iter__
      results = compiler.execute_sql(
                ^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
      cursor.execute(sql, params)
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
      return self._execute_with_wrappers(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
      return executor(sql, params, many, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
      with self.db.wrap_database_errors:
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
    File "/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
      return self.cursor.execute(sql, params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/django_prometheus/db/common.py", line 69, in execute
      return super().execute(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/ak-root/venv/lib/python3.11/site-packages/psycopg/cursor.py", line 737, in execute
      raise ex.with_traceback(None)
  django.db.utils.ProgrammingError: relation "authentik_stages_authenticator_static_staticdevice" does not exist
  LINE 1: ...tic_staticdevice"."throttling_failure_count" FROM "authentik...
                                                               ^
  ```
  </details>
  
  
  **Version and Deployment (please complete the following information):**
  - authentik version: gh-next as of 10/21/2023
  - Deployment: docker-compose
  
  **Additional context**
  Add any other context about the problem here.
          
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `lifecycle/system_migrations/otp_merge.py`
  Content:
  ```
  1 # flake8: noqa
  2 from lifecycle.migrate import BaseMigration
  3 
  4 SQL_STATEMENT = """
  5 DELETE FROM django_migrations WHERE app = 'otp_static';
  6 DELETE FROM django_migrations WHERE app = 'otp_totp';
  7 -- Rename tables (static)
  8 ALTER TABLE otp_static_staticdevice RENAME TO authentik_stages_authenticator_static_staticdevice;
  9 ALTER TABLE otp_static_statictoken RENAME TO authentik_stages_authenticator_static_statictoken;
  10 ALTER SEQUENCE otp_static_statictoken_id_seq RENAME TO authentik_stages_authenticator_static_statictoken_id_seq;
  11 ALTER SEQUENCE otp_static_staticdevice_id_seq RENAME TO authentik_stages_authenticator_static_staticdevice_id_seq;
  12 -- Rename tables (totp)
  13 ALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice;
  14 ALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq;
  15 """
  16 
  17 
  18 class Migration(BaseMigration):
  19     def needs_migration(self) -> bool:
  20         self.cur.execute(
  21             "select * from information_schema.tables WHERE table_name='otp_static_staticdevice'"
  22         )
  23         return bool(self.cur.rowcount)
  24 
  25     def run(self):
  26         self.cur.execute(SQL_STATEMENT)
  27         self.fake_migration(
  28             (
  29                 "authentik_stages_authenticator_static",
  30                 "0008_initial",
  31             ),
  32             (
  33                 "authentik_stages_authenticator_static",
  34                 "0009_throttling",
  35             ),
  36             (
  37                 "authentik_stages_authenticator_totp",
  38                 "0008_initial",
  39             ),
  40             (
  41                 "authentik_stages_authenticator_totp",
  42                 "0009_auto_20190420_0723",
  43             ),
  44         )
  45
  ```
  --- 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/lifecycle/system_migrations/otp_merge.py b/lifecycle/system_migrations/otp_merge.py
  --- a/lifecycle/system_migrations/otp_merge.py
  +++ b/lifecycle/system_migrations/otp_merge.py
  @@ -2,6 +2,7 @@
   from lifecycle.migrate import BaseMigration
   
   SQL_STATEMENT = """
  +BEGIN TRANSACTION;
   DELETE FROM django_migrations WHERE app = 'otp_static';
   DELETE FROM django_migrations WHERE app = 'otp_totp';
   -- Rename tables (static)
  @@ -12,6 +13,7 @@
   -- Rename tables (totp)
   ALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice;
   ALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq;
  +COMMIT;
   """
  
verification_info: {"golden_diff": "diff --git a/lifecycle/system_migrations/otp_merge.py b/lifecycle/system_migrations/otp_merge.py\n--- a/lifecycle/system_migrations/otp_merge.py\n+++ b/lifecycle/system_migrations/otp_merge.py\n@@ -2,6 +2,7 @@\n from lifecycle.migrate import BaseMigration\n \n SQL_STATEMENT = \"\"\"\n+BEGIN TRANSACTION;\n DELETE FROM django_migrations WHERE app = 'otp_static';\n DELETE FROM django_migrations WHERE app = 'otp_totp';\n -- Rename tables (static)\n@@ -12,6 +13,7 @@\n -- Rename tables (totp)\n ALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice;\n ALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq;\n+COMMIT;\n \"\"\"\n", "issue": "Login fails at GET /api/v3/flows/executor/default-authentication-flow/ \n**Describe the bug**\r\nAuthentication fails.  I've tried my own auth flow, which includes a passwordless option.  This log is from switching back to the default auth flow.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Enter Username\r\n2. Enter Password\r\n3. Press Enter\r\n4. See error\r\n\r\n**Expected behavior**\r\nThis stage would normally be to select the authenticator to use.  (Key or TOTP, in my case)\r\n\r\n**Screenshots**\r\nIf applicable, add screenshots to help explain your problem.\r\n\r\n**Logs**\r\n<details>\r\n    <summary>Stacktrace from authentik</summary>\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/authentik/flows/views/executor.py\", line 287, in get\r\n    stage_response = self.current_stage_view.dispatch(request)\r\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/views/generic/base.py\", line 143, in dispatch\r\n    return handler(request, *args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/authentik/stages/authenticator_validate/stage.py\", line 222, in get\r\n    challenges = self.get_device_challenges()\r\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/authentik/stages/authenticator_validate/stage.py\", line 157, in get_device_challenges\r\n    user_devices = list(devices_for_user(self.get_pending_user()))\r\n                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/authentik/stages/authenticator/__init__.py\", line 93, in devices_for_user\r\n    yield from device_set\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py\", line 398, in __iter__\r\n    self._fetch_all()\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py\", line 1881, in _fetch_all\r\n    self._result_cache = list(self._iterable_class(self))\r\n                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/models/query.py\", line 91, in __iter__\r\n    results = compiler.execute_sql(\r\n              ^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py\", line 1562, in execute_sql\r\n    cursor.execute(sql, params)\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py\", line 67, in execute\r\n    return self._execute_with_wrappers(\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py\", line 80, in _execute_with_wrappers\r\n    return executor(sql, params, many, context)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\n    with self.db.wrap_database_errors:\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/utils.py\", line 91, in __exit__\r\n    raise dj_exc_value.with_traceback(traceback) from exc_value\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django/db/backends/utils.py\", line 89, in _execute\r\n    return self.cursor.execute(sql, params)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/django_prometheus/db/common.py\", line 69, in execute\r\n    return super().execute(*args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/ak-root/venv/lib/python3.11/site-packages/psycopg/cursor.py\", line 737, in execute\r\n    raise ex.with_traceback(None)\r\ndjango.db.utils.ProgrammingError: relation \"authentik_stages_authenticator_static_staticdevice\" does not exist\r\nLINE 1: ...tic_staticdevice\".\"throttling_failure_count\" FROM \"authentik...\r\n                                                             ^\r\n```\r\n</details>\r\n\r\n\r\n**Version and Deployment (please complete the following information):**\r\n- authentik version: gh-next as of 10/21/2023\r\n- Deployment: docker-compose\r\n\r\n**Additional context**\r\nAdd any other context about the problem here.\r\n        \n", "before_files": [{"content": "# flake8: noqa\nfrom lifecycle.migrate import BaseMigration\n\nSQL_STATEMENT = \"\"\"\nDELETE FROM django_migrations WHERE app = 'otp_static';\nDELETE FROM django_migrations WHERE app = 'otp_totp';\n-- Rename tables (static)\nALTER TABLE otp_static_staticdevice RENAME TO authentik_stages_authenticator_static_staticdevice;\nALTER TABLE otp_static_statictoken RENAME TO authentik_stages_authenticator_static_statictoken;\nALTER SEQUENCE otp_static_statictoken_id_seq RENAME TO authentik_stages_authenticator_static_statictoken_id_seq;\nALTER SEQUENCE otp_static_staticdevice_id_seq RENAME TO authentik_stages_authenticator_static_staticdevice_id_seq;\n-- Rename tables (totp)\nALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice;\nALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq;\n\"\"\"\n\n\nclass Migration(BaseMigration):\n    def needs_migration(self) -> bool:\n        self.cur.execute(\n            \"select * from information_schema.tables WHERE table_name='otp_static_staticdevice'\"\n        )\n        return bool(self.cur.rowcount)\n\n    def run(self):\n        self.cur.execute(SQL_STATEMENT)\n        self.fake_migration(\n            (\n                \"authentik_stages_authenticator_static\",\n                \"0008_initial\",\n            ),\n            (\n                \"authentik_stages_authenticator_static\",\n                \"0009_throttling\",\n            ),\n            (\n                \"authentik_stages_authenticator_totp\",\n                \"0008_initial\",\n            ),\n            (\n                \"authentik_stages_authenticator_totp\",\n                \"0009_auto_20190420_0723\",\n            ),\n        )\n", "path": "lifecycle/system_migrations/otp_merge.py"}], "after_files": [{"content": "# flake8: noqa\nfrom lifecycle.migrate import BaseMigration\n\nSQL_STATEMENT = \"\"\"\nBEGIN TRANSACTION;\nDELETE FROM django_migrations WHERE app = 'otp_static';\nDELETE FROM django_migrations WHERE app = 'otp_totp';\n-- Rename tables (static)\nALTER TABLE otp_static_staticdevice RENAME TO authentik_stages_authenticator_static_staticdevice;\nALTER TABLE otp_static_statictoken RENAME TO authentik_stages_authenticator_static_statictoken;\nALTER SEQUENCE otp_static_statictoken_id_seq RENAME TO authentik_stages_authenticator_static_statictoken_id_seq;\nALTER SEQUENCE otp_static_staticdevice_id_seq RENAME TO authentik_stages_authenticator_static_staticdevice_id_seq;\n-- Rename tables (totp)\nALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice;\nALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq;\nCOMMIT;\n\"\"\"\n\n\nclass Migration(BaseMigration):\n    def needs_migration(self) -> bool:\n        self.cur.execute(\n            \"select * from information_schema.tables WHERE table_name='otp_static_staticdevice'\"\n        )\n        return bool(self.cur.rowcount)\n\n    def run(self):\n        self.cur.execute(SQL_STATEMENT)\n        self.fake_migration(\n            (\n                \"authentik_stages_authenticator_static\",\n                \"0008_initial\",\n            ),\n            (\n                \"authentik_stages_authenticator_static\",\n                \"0009_throttling\",\n            ),\n            (\n                \"authentik_stages_authenticator_totp\",\n                \"0008_initial\",\n            ),\n            (\n                \"authentik_stages_authenticator_totp\",\n                \"0009_auto_20190420_0723\",\n            ),\n        )\n", "path": "lifecycle/system_migrations/otp_merge.py"}]}