Repository: goauthentik/authentik

Issue:
General system exception - Event Log
**Describe the bug**
Getting a "General system exception" in the Event log, after the user logged in

**To Reproduce**
Steps to reproduce the behavior:

1. Default [default-authentication-flow]
2. between default-authentication-identification and default-authentication-password there is a Prompt Stage with Checkbox ("I'm not a Robot")
3. User login
4. Exception in the Event Log

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
![image](https://github.com/goauthentik/authentik/assets/159008007/7ff5b83e-433e-472d-b403-3e526f51f3d0)
![image](https://github.com/goauthentik/authentik/assets/159008007/de46baf0-6d43-42dd-9649-99afb8d165aa)


**Logs**
Property Mappings Exception:

ExceptionTraceback (most recent call last):   File "/authentik/lib/expression/evaluator.py", line 198, in evaluate     ast_obj = self.compile(expression_source)               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/authentik/lib/expression/evaluator.py", line 187, in compile     return compile(self.wrap_expression(expression, param_keys), self._filename, "exec")            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ builtins.IndentationError: expected an indented block after function definition on line 1 (Checkbox, line 3)
--


General system exception:

Traceback (most recent call last):
  File "/ak-root/venv/lib/python3.12/site-packages/celery/app/trace.py", line 494, in trace_task
    I, R, state, retval = on_error(task_request, exc)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/celery/app/trace.py", line 399, in on_error
    R = I.handle_error_state(
        ^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/celery/app/trace.py", line 178, in handle_error_state
    return {
           ^
  File "/ak-root/venv/lib/python3.12/site-packages/celery/app/trace.py", line 236, in handle_failure
    task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
  File "/authentik/events/system_tasks.py", line 106, in on_failure
    DBSystemTask.objects.update_or_create(
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/query.py", line 986, in update_or_create
    obj, created = self.select_for_update().get_or_create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/query.py", line 955, in get_or_create
    return self.create(**params), True
           ^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/query.py", line 679, in create
    obj.save(force_insert=True, using=self.db)
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py", line 822, in save
    self.save_base(
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py", line 909, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1067, in _save_table
    results = self._do_insert(
              ^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1108, in _do_insert
    return manager._insert(
           ^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1847, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1823, in execute_sql
    cursor.execute(sql, params)
  File "/ak-root/venv/lib/python3.12/site-packages/sentry_sdk/integrations/django/__init__.py", line 641, in execute
    result = real_execute(self, sql, params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/django_prometheus/db/common.py", line 69, in execute
    return super().execute(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 728, in execute
    self._conn.wait(
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/connection.py", line 969, in wait
    return waiting.wait(gen, self.pgconn.socket, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_c/_psycopg/waiting.pyx", line 190, in psycopg_c._psycopg.wait_c
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 210, in _execute_gen
    pgq = self._convert_query(query, params)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/client_cursor.py", line 79, in _convert_query
    pgq.convert(query, params)
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/_queries.py", line 213, in convert
    self.dump(vars)
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/_queries.py", line 223, in dump
    self.params = tuple(
                  ^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/_queries.py", line 224, in <genexpr>
    self._tx.as_literal(p) if p is not None else b"NULL" for p in params
    ^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_c/_psycopg/transform.pyx", line 206, in psycopg_c._psycopg.Transformer.as_literal
  File "psycopg_c/_psycopg/transform.pyx", line 215, in psycopg_c._psycopg.Transformer.as_literal
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/adapt.py", line 57, in quote
    value = self.dump(obj)
            ^^^^^^^^^^^^^^
  File "/ak-root/venv/lib/python3.12/site-packages/psycopg/types/json.py", line 151, in dump
    data = dumps(obj)
           ^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
builtins.TypeError: Object of type UUID is not JSON serializable


General system exception:

Traceback (most recent call last):
builtins.TypeError: Object of type UUID is not JSON serializable

**Version and Deployment (please complete the following information):**

-   authentik version: 2024.2.0
-   Deployment: Docker

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/authentik/events/system_tasks.py b/authentik/events/system_tasks.py
--- a/authentik/events/system_tasks.py
+++ b/authentik/events/system_tasks.py
@@ -88,8 +88,8 @@ def after_return(self, status, retval, task_id, args: list[Any], kwargs: dict[st
                 "duration": max(perf_counter() - self._start_precise, 0),
                 "task_call_module": self.__module__,
                 "task_call_func": self.__name__,
-                "task_call_args": args,
-                "task_call_kwargs": kwargs,
+                "task_call_args": sanitize_item(args),
+                "task_call_kwargs": sanitize_item(kwargs),
                 "status": self._status,
                 "messages": sanitize_item(self._messages),
                 "expires": now() + timedelta(hours=self.result_timeout_hours),
@@ -113,8 +113,8 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
                 "duration": max(perf_counter() - self._start_precise, 0),
                 "task_call_module": self.__module__,
                 "task_call_func": self.__name__,
-                "task_call_args": args,
-                "task_call_kwargs": kwargs,
+                "task_call_args": sanitize_item(args),
+                "task_call_kwargs": sanitize_item(kwargs),
                 "status": self._status,
                 "messages": sanitize_item(self._messages),
                 "expires": now() + timedelta(hours=self.result_timeout_hours),


Test patch: