Question

All documentation of this method that I can find says that Queue.write returns True or False, depending on whether the write succeeded, but this doesn't square with reality.

The docs say:

The write method returns a True if everything went well. If the write didn't succeed it will either return a False (meaning SQS simply chose not to write the message for some reason) or an exception if there was some sort of problem with the request.

But in fact the method simply returns the message that gets passed in. Here is the relevant source code from https://github.com/boto/boto/blob/develop/boto/sqs/queue.py:

def write(self, message, delay_seconds=None):
    """
    Add a single message to the queue.
    :type message: Message
    :param message: The message to be written to the queue

    :rtype: :class:`boto.sqs.message.Message`
    :return: The :class:`boto.sqs.message.Message` object that was written.
    """
    new_msg = self.connection.send_message(self,
                                           message.get_body_encoded(),
                                           delay_seconds)
    message.id = new_msg.id
    message.md5 = new_msg.md5
    return message

My question then is: How do I really tell if the write was successful?

Était-ce utile?

La solution

The documentation quote you provide comes from the SQS tutorial. The SQS API docs correctly describe the current return value. The SQS tutorial is simply out of date and needs to be corrected. I have created an issue to track this.

If the write fails for any reason, the service will return an HTTP error code which, in turn, will cause boto to raise an SQSError exception. If no exception is raised, the write was successful.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top