Skip to content

[BUG] Context manager not working with MessageQueue #2035

Closed
@DemianS

Description

@DemianS

Steps to reproduce

  1. Set up a bot with a MessageQueue as described in the wiki

  2. Override methods send_document, send_photo with @messagequeue.queuedmessage decorator

  3. Open file with context manager and try to send it

Expected behaviour

Files must be sent to chat as usual, like they do without MessageQueue

Actual behaviour

Files are not sent. As I found, file is closed at the moment it should have sent.
And we have: ValueError: read of closed file of course.

Why this happens and how to overcome that (steal that topic)

Files are closed before actual send, because send_document returns Promise object instead of message, you know, because it's messagequeue. So that Promise results after context manager close this file.
HotFix: You should wait for promise.result() if you want to close file properly.
Or InputFile should close file after it is done with it, and you don't have to worry about it.

Hope I fill everything right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions