Repository: goauthentik/authentik

Issue:
Cannot `ak export_blueprint`
**Describe the bug**
A clear and concise description of what the bug is.

Cannot export blueprints

**To Reproduce**
Steps to reproduce the behavior:

1. Go to CLI
2. Run `ak export_blueprint`
3. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

Export to work

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Logs**
Output of docker-compose logs or kubectl logs respectively

```shell
I have no name!@8d8c217ec3cb:/$ ak export_blueprint
{"event": "Loaded config", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894152.8936794, "file": "/authentik/lib/default.yml"}
{"event": "Loaded environment variables", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894152.8940713, "count": 16}
{"event": "Booting authentik", "level": "info", "logger": "authentik.lib.config", "timestamp": 1708894155.2659028, "version": "2024.2.1"}
{"event": "Enabled authentik enterprise", "level": "info", "logger": "authentik.lib.config", "timestamp": 1708894155.2674916}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2684987, "path": "authentik.enterprise.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.270752, "path": "authentik.sources.oauth.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.271197, "path": "authentik.admin.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2718306, "path": "authentik.crypto.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.273662, "path": "authentik.outposts.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2757123, "path": "authentik.sources.plex.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2763362, "path": "authentik.blueprints.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2765484, "path": "authentik.enterprise.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2771592, "path": "authentik.events.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2786143, "path": "authentik.stages.authenticator_totp.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.279584, "path": "authentik.sources.ldap.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.2801015, "path": "authentik.policies.reputation.settings"}
{"event": "Loaded app settings", "level": "debug", "logger": "authentik.lib.config", "timestamp": 1708894155.282106, "path": "authentik.providers.scim.settings"}
/ak-root/venv/lib/python3.12/site-packages/opencontainers/distribution/reggie/defaults.py:17: SyntaxWarning: invalid escape sequence '\('
  "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
{"domain_url": null, "event": "Loaded MMDB database", "file": "/geoip/GeoLite2-ASN.mmdb", "last_write": 1708616240.0, "level": "info", "logger": "authentik.events.context_processors.mmdb", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:16.400106"}
{"domain_url": null, "event": "Loaded MMDB database", "file": "/geoip/GeoLite2-City.mmdb", "last_write": 1708616239.0, "level": "info", "logger": "authentik.events.context_processors.mmdb", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:16.401503"}
{"app_name": "authentik.tenants", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.tenants.checks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:16.898219"}
/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.
  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
{"app_name": "authentik.admin", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.admin.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.019825"}
{"app_name": "authentik.admin", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.admin.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.020820"}
{"app_name": "authentik.crypto", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.crypto.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.025835"}
{"app_name": "authentik.flows", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.flows.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.633566"}
{"app_name": "authentik.outposts", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.outposts.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.708761"}
{"app_name": "authentik.outposts", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.outposts.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.709747"}
{"domain_url": null, "event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 80245, "schema_name": "public", "task_id": "fa4f2b8497be488c9c35b5c1288d9744", "task_name": "authentik.outposts.tasks.outpost_post_save", "timestamp": "2024-02-25T20:49:17.796160"}
{"app_name": "authentik.policies.reputation", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.policies.reputation.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.799304"}
{"app_name": "authentik.policies.reputation", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.policies.reputation.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.800787"}
{"app_name": "authentik.policies", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.policies.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.815401"}
{"app_name": "authentik.providers.proxy", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.providers.proxy.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.818114"}
{"app_name": "authentik.providers.proxy", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.providers.proxy.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:17.818919"}
{"app_name": "authentik.providers.scim", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.providers.scim.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.102123"}
{"app_name": "authentik.providers.scim", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.providers.scim.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.102929"}
{"app_name": "authentik.rbac", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.rbac.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.107089"}
{"app_name": "authentik.sources.ldap", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.sources.ldap.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.117740"}
{"app_name": "authentik.sources.ldap", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.sources.ldap.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.120107"}
{"app_name": "authentik.sources.oauth", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.sources.oauth.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.122458"}
/ak-root/venv/lib/python3.12/site-packages/facebook/__init__.py:99: SyntaxWarning: invalid escape sequence '\d'
  version_regex = re.compile("^\d\.\d{1,2}$")
{"app_name": "authentik.sources.saml", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.sources.saml.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.132635"}
{"app_name": "authentik.stages.authenticator_duo", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.stages.authenticator_duo.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.134490"}
{"app_name": "authentik.stages.authenticator_static", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.stages.authenticator_static.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.136177"}
{"app_name": "authentik.stages.email", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.stages.email.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.137420"}
{"domain_url": null, "event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 80245, "schema_name": "public", "task_id": "a81cc1d56a1245d4bb12ee7f85e98ceb", "task_name": "authentik.blueprints.v1.tasks.blueprints_discovery", "timestamp": "2024-02-25T20:49:18.156872"}
{"domain_url": null, "event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 80245, "schema_name": "public", "task_id": "056723db9c534d5d92745d3538d0f143", "task_name": "authentik.blueprints.v1.tasks.clear_failed_blueprints", "timestamp": "2024-02-25T20:49:18.158503"}
{"app_name": "authentik.core", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.core.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.160190"}
{"app_name": "authentik.core", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.core.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.160368"}
{"app_name": "authentik.enterprise", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.enterprise.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.172977"}
{"app_name": "authentik.enterprise", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.enterprise.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.173643"}
{"app_name": "authentik.enterprise.providers.rac", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.enterprise.providers.rac.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.182638"}
{"app_name": "authentik.events", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.events.tasks", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.184035"}
{"app_name": "authentik.events", "domain_url": null, "event": "Imported related module", "level": "info", "logger": "authentik.blueprints.apps", "module": "authentik.events.signals", "pid": 80245, "schema_name": "public", "timestamp": "2024-02-25T20:49:18.184141"}
{"domain_url": null, "event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 80245, "schema_name": "public", "task_id": "a5237ac2af9b4d9ca4c08339aa419519", "task_name": "authentik.core.tasks.clean_temporary_users", "timestamp": "2024-02-25T20:49:18.202065"}
Switching to schema 'public'
/authentik/crypto/api.py:75: CryptographyDeprecationWarning: Properties that return a naïve datetime object have been deprecated. Please switch to not_valid_after_utc.
  return DateTimeField().to_representation(instance.certificate.not_valid_after)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/manage.py", line 31, in <module>
    execute_from_command_line(sys.argv)
  File "/ak-root/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/ak-root/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/ak-root/venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/ak-root/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/authentik/tenants/management/__init__.py", line 38, in handle
    self.handle_per_tenant(*args, **options)
  File "/ak-root/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/authentik/blueprints/management/commands/export_blueprint.py", line 19, in handle_per_tenant
    self.stdout.write(exporter.export_to_string())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/authentik/blueprints/v1/exporter.py", line 72, in export_to_string
    blueprint = self.export()
                ^^^^^^^^^^^^^
  File "/authentik/blueprints/v1/exporter.py", line 67, in export
    blueprint.entries = list(self.get_entries())
                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/authentik/blueprints/v1/exporter.py", line 45, in get_entries
    yield BlueprintEntry.from_model(obj)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/authentik/blueprints/v1/common.py", line 85, in from_model
    all_attrs = get_attrs(model)
                ^^^^^^^^^^^^^^^^
  File "/authentik/blueprints/v1/common.py", line 29, in get_attrs
    data = dict(serializer.data)
                ^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 555, in data
    ret = super().data
          ^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 253, in data
    self._data = self.to_representation(self.instance)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 522, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 522, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/rest_framework/fields.py", line 1838, in to_representation
    return method(value)
           ^^^^^^^^^^^^^
  File "/authentik/core/api/users.py", line 157, in get_avatar
    return get_avatar(user, self.context["request"])
                            ~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'request'
```

**Version and Deployment (please complete the following information):**

-   authentik version: 2024.2.1
-   Deployment: docker-compose

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/authentik/core/api/users.py b/authentik/core/api/users.py
--- a/authentik/core/api/users.py
+++ b/authentik/core/api/users.py
@@ -154,7 +154,7 @@ def _set_password(self, instance: User, password: str | None):
 
     def get_avatar(self, user: User) -> str:
         """User's avatar, either a http/https URL or a data URI"""
-        return get_avatar(user, self.context["request"])
+        return get_avatar(user, self.context.get("request"))
 
     def validate_path(self, path: str) -> str:
         """Validate path"""
@@ -218,7 +218,7 @@ class UserSelfSerializer(ModelSerializer):
 
     def get_avatar(self, user: User) -> str:
         """User's avatar, either a http/https URL or a data URI"""
-        return get_avatar(user, self.context["request"])
+        return get_avatar(user, self.context.get("request"))
 
     @extend_schema_field(
         ListSerializer(


Test patch: