Skip to content

fix: Ensure that ctx and env __init__ arguments are always wrapped#131

Open
hoodmane wants to merge 1 commit into
cloudflare:mainfrom
hoodmane:hoodmane/fix-wrap-init-args
Open

fix: Ensure that ctx and env __init__ arguments are always wrapped#131
hoodmane wants to merge 1 commit into
cloudflare:mainfrom
hoodmane:hoodmane/fix-wrap-init-args

Conversation

@hoodmane

Copy link
Copy Markdown
Contributor

We fixed the double-wrapping problem in #126 but added a new problem that ctx and env args in subclasses won't be wrapped at all. This switches to wrapping all init functions but making DurableObjectContext and _EnvWrapper idempotent so that double wrapping them is not possible.

We fixed the double-wrapping problem in cloudflare#126 but added a new problem that ctx
and env args in subclasses won't be wrapped at all. This switches to wrapping
all __init__ functions but making DurableObjectContext and _EnvWrapper
idempotent so that double wrapping them is not possible.
def __init_subclass__(cls, **_kwargs):
if _is_direct_binding_subclass(cls, DurableObject):
_wrap_subclass(cls)
_wrap_class(cls)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need both decorator + __init_subclass__?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

@ryanking13 ryanking13 Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, this class wrapping thing is really making my head confused

return cls


def _wrap_workflow_step(cls):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess calling _wrap_workflow_step twice would still wrap run function twice

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah these need to be adjusted too that is right.

_wrap_subclass(cls)
_wrap_queue_handler(cls)
_wrap_class(cls)
_wrap_queue_handler(cls)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same for queue. the queue function would be wrapped twice I guess?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants