Skip to content

Filter on state in handler does not work correctly when updating state in middleware #1411

Answered by JrooTJunior
V0ch0n0k asked this question in Q&A
Discussion options

You must be logged in to vote

Expected behavior.

You should not change any user state in the middleware or send any messages from it.

State filter has no any state loading mechanism in due to performance optimizations. FSM Middleware loads user state to the event context and then FSM filter check user state only from the context.


Seems like you want to separate functionality for anonymous and registered users, so, you should detect that user is registered or no and put this information into the context and then check it by filters, for example (pseudocode):

dispatcher = Dispatcher()
dispatcher.include_routers(
    anonymous_router,  # Should be imported
    registered_router, # Should be imported
    ...
)

@dp.update.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by V0ch0n0k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants