inngest / inngest-py

Python SDK for Inngest
https://www.inngest.com/docs/reference/python
Apache License 2.0
24 stars 6 forks source link

Django integration does not send valid traceback on exceptions #109

Closed hugodutka closed 2 months ago

hugodutka commented 2 months ago

Hi! I'm using Inngest with Django on sdk version 0.3.16. I noticed that when a step fails Inngest does not show the exception traceback but instead Django-generated HTML with a "500 server error" message.

2024-05-31 17 09 22

I traced the issue to this line in the Django integration:

https://github.com/inngest/inngest-py/blob/b1d79840491333ce37e4aff7e491432560e449d0/inngest/django.py#L284

The preceding line is:

https://github.com/inngest/inngest-py/blob/b1d79840491333ce37e4aff7e491432560e449d0/inngest/django.py#L283

so body is always a string. When I locally changed the line to:

if isinstance(comm_res.body, Exception):

I could see a proper traceback in the Inngest UI.

Would you be able to implement the fix? Thanks!

goodoldneon commented 2 months ago

Which version of Django are you using? I ran the following function using Django 4.2 and I see the error in our Dev Server UI:

@client.create_function(
    fn_id="my-fn",
    retries=0,
    trigger=inngest.TriggerEvent(event="my-event"),
)
def fn(
    ctx: inngest.Context,
    step: inngest.StepSync,
) -> None:
    def _step_1() -> None:
        raise Exception("This is an error")

    step.run("step-1", _step_1)

image

so body is always a string

body won't always be a string because transforms.dump_json returns errors instead of raising, since our engineers prefer errors as values (we have a blog post!). We still raise errors for user-facing stuff since Pythonistas overwhelmingly prefer that, but internally we use errors as values https://github.com/inngest/inngest-py/blob/b1d79840491333ce37e4aff7e491432560e449d0/inngest/_internal/transforms.py#L32-L36

goodoldneon commented 2 months ago

Also, could you give version 0.4.0a1 of our SDK a try? We refactored some stuff that may help. Here's a migration guide (there are few non-middleware breaking changes): https://www.inngest.com/docs/reference/python/migrations/v0.3-to-v0.4

hugodutka commented 2 months ago

I'm using Django 5.0.6 and async functions and steps. I will give 0.4 a try and report back.

hugodutka commented 2 months ago

Traceback is correctly shown with 0.4.0a1. Thanks! I'm closing the issue.

goodoldneon commented 2 months ago

Great! We'll publish a proper 0.4.0 release next week. 0.4.0a1 seems stable but it's technically a prerelease 😄