Skip to content

[BUG] Context manager not working with MessageQueue #2035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DemianS opened this issue Jul 29, 2020 · 2 comments
Closed

[BUG] Context manager not working with MessageQueue #2035

DemianS opened this issue Jul 29, 2020 · 2 comments

Comments

@DemianS
Copy link

DemianS commented Jul 29, 2020

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.

@Bibo-Joshi
Copy link
Member

A solution specifically for InputFile would be to have Promise already construct the InputFile, something along the lines

        new_args = []
        for arg in self.args:
            if InputFile.is_file(arg):
                new_args.append(InputFile(arg))
            else:
                new_args.append(arg)
        self.args = tuple(new_args)
        for key, value in self.kwargs.items():
            if InputFile.is_file(value):
                self.kwargs[key] = InputFile(value)

We would need to check, if we would need to handle more things like this, but at least atm I can't think of anything else …

@Bibo-Joshi
Copy link
Member

As we won't tackle this issue individually but in the context of #2139, I will close this. #2139 links here, so it won't be forgotten :)

@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants