Closed qvvvvq closed 2 months ago
This is a known problem with sessions in conversations. What happens is essentially that you're modifying an old context object that has already written back its session data. What's why modifying it has no effect.
There is conversation.session
which you should use instead. It selects the current context object and thus makes sure the data is persisted.
This is documented here: https://grammy.dev/plugins/conversations#rule-iii-use-convenience-functions
Hi, I'm encountering an issue with session persistence when using conversations in grammy. After modifying the session inside a conversation, the session reverts to its default values in the global middleware after the conversation ends. I expect the session to retain the modified values, but it seems to reset instead.
Hereβs a simplified version of the code:
The output Iβm seeing:
In the conversation, the session value updates correctly (ctx.session:myConversation:after shows the new value), but after the conversation completes, the global logMiddleware still shows the default session values.
Expected Behavior: The session should retain the updated values after the conversation ends.
Actual Behavior: The session resets to the default values in the global middleware after the conversation finishes.
Am I missing something about how session updates are handled after conversations, or is this a potential issue?
Thank you for your help!