Skip to content

Conversation

@Andrey-Omelyanuk
Copy link

@Andrey-Omelyanuk Andrey-Omelyanuk commented Dec 11, 2025

  File "/home/app/.venv/lib/python3.12/site-packages/celery/app/task.py", line 601, in apply_async
    return app.send_task(
           ^^^^^^^^^^^^^^
  File "/home/app/.venv/lib/python3.12/site-packages/celery/app/base.py", line 930, in send_task
    amqp.send_task_message(P, name, message, **options)
  File "/home/app/.venv/lib/python3.12/site-packages/celery/app/amqp.py", line 523, in send_task_message
    ret = producer.publish(
          ^^^^^^^^^^^^^^^^^
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/messaging.py", line 178, in publish
    body, content_type, content_encoding = self._prepare(
                                           ^^^^^^^^^^^^^^
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/messaging.py", line 280, in _prepare
    body) = dumps(body, serializer=serializer)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/serialization.py", line 219, in dumps
    with _reraise_errors(EncodeError):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/serialization.py", line 45, in _reraise_errors
    reraise(wrapper, wrapper(exc), sys.exc_info()[2])
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/exceptions.py", line 34, in reraise
    raise value.with_traceback(tb)
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/serialization.py", line 41, in _reraise_errors
    yield
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/serialization.py", line 220, in dumps
    payload = encoder(data)
              ^^^^^^^^^^^^^
  File "/home/app/.venv/lib/python3.12/site-packages/kombu/utils/json.py", line 63, in dumps
    return _dumps(s, cls=cls, **dict(default_kwargs, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 238, in dumps
    **kw).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 "/home/app/.venv/lib/python3.12/site-packages/kombu/utils/json.py", line 47, in default
    return super().default(o)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
kombu.exceptions.EncodeError: Object of type CeleryTransition is not JSON serializable

Celery tasks complete_transition, fail_transition, run_side_effects_as_task and run_callbacks_as_task received transition in args as object, but it can be not JSON serializable.
My proposal to push action_name/transition_name to arg instead of obj.

from core.logic.side_effects import long_action

class UserLockerProcess(Process):
    transitions = [
        ...
        Transition(
            action_name='lock',
            sources=[LOCK_STATES.open],
            target=LOCK_STATES.locked,
            side_effects=[
                long_action,    # simulate long action
            ],
        ),
        ...
    ]

Also added Dockerfile and makefile for local development.


Note

Replaces non-serializable Transition objects in Celery task payloads with action_name lookup, adds kwargs sanitization, updates task queuing/tests, and adds Dockerfile/makefile for local dev.

  • Celery commands:
    • Replace passing transition objects with action_name across complete_transition, fail_transition, run_side_effects_as_task, and run_callbacks_as_task.
    • Add recursive helpers _find_transition_in_process and get_transition_from_process to resolve transitions at runtime (including nested processes).
    • Sanitize task kwargs in CeleryCommandMixin.get_task_kwargs (skip callables, convert user to user_id, allow primitives, carry exception).
    • Convert side-effect command callables to task names before queuing; adjust chains/groups accordingly.
    • Update logging formats to use action_name.
  • Tests:
    • Update demo/tests/test_process.py expectations to include action_name and serialized kwargs; remove reliance on transition object.
  • Tooling:
    • Add Dockerfile and makefile for local development (build, test, shell).

Written by Cursor Bugbot for commit ce10faa. This will update automatically on new commits. Configure here.

for key, value in kwargs.items():
if key == 'exception':
serializable_kwargs[key] = value
continue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Exception objects passed to Celery are not JSON serializable

The code explicitly passes exception objects through to serializable_kwargs without any serialization. When key == 'exception', the value (a Python exception object) is included directly in the kwargs that get passed to Celery task signatures. Since Python exception objects are not JSON serializable, this will cause the same type of kombu.exceptions.EncodeError that this PR aims to fix. The exception needs to be converted to a string representation (e.g., str(value)) or excluded from the Celery task kwargs entirely.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant