Skip to content

Cache middleware properly#9

Merged
pencil merged 1 commit intomainfrom
middleware-cache-fix
Jun 23, 2025
Merged

Cache middleware properly#9
pencil merged 1 commit intomainfrom
middleware-cache-fix

Conversation

@pencil
Copy link
Collaborator

@pencil pencil commented Jun 17, 2025

Because of how the double underscore prefix (__) works, hasattr(self, "__cached_middleware") never returned true and the for middleware in self.broker.middleware loop ran on every invocation. This PR fixes the problem by moving to a single _ prefix. Alternatively we could check for hasattr(self, "_Workflow__cached_middleware") but that feels like assuming a CPython implementation detail.

I also considered using @cached_property but that uses __dict__ internally which is potentially problematic from a memory perspective since a Workflow can be gigantic.

Copy link
Collaborator

@dan-woz dan-woz left a comment

Choose a reason for hiding this comment

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

Ah yes, the dangers of implementing private access on vibes.

@pencil pencil merged commit 89a563e into main Jun 23, 2025
9 checks passed
@pencil pencil deleted the middleware-cache-fix branch June 23, 2025 17:53
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