Message.create_messages should be a generator

Bug #1469324 reported by Brian Curtin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack SDK
Invalid
High
Unassigned

Bug Description

the Message.create_messages method in openstack/message/v1/message.py should yield messages instead of build up a list to be returned.

Revision history for this message
Everett Toews (everett-toews) wrote :

I actually had it this way to begin with but ultimately left the yield out. Here's why.

As I was coding up the functional tests, I found I was just calling only

    self.conn.message.create_messages(messages)

a lot because I just need to create some messages and move on. If it succeeds, I don't really care too much about the result. I know the messages are on the queue and that's all I care about. Or raises an exception and I deal with it and there's no result to process in that case.

I expect this use case is pretty common. Fire and forget messages. It's the nature of queues.

But if it's a generator, I have to do something like

    list(self.conn.message.create_messages(messages))

just to get it to run and actually make the call to create messages. I don't care about the result but I have to wrap it in list(). It seems like a gotcha to me. Someone could easily forget to wrap it and the messages never get created.

Also a generator doesn't add a lot of efficiency here either. The messages already consume whatever memory they do and we're just adding the href to them in the result.

And I haven't come across any other bulk create methods that return a generator as a precedent. The only one's I know of are the bulk create methods in Networks [1] but those don't seem to be implemented in the proxy.

I'm certainly open to discussing the implementation but am leaning towards leaving it as is for the reasons above.

[1] http://developer.openstack.org/api-ref-networking-v2.html

Revision history for this message
Brian Curtin (brian.curtin) wrote :

Yeah, the wrapping with list() thing is really only something you should be doing manually when toying around in the interpreter, or sometimes we do them in tests because of the way unittest methods work. It's not how you would write real code.

Create returning a list is weird for this SDK, and I don't think anyone else does it. This is unfortunate, but I guess this can return a list for now. A tiny part of me thinks it should just drop the returned messages entirely and make you get them from a list call, but I don't understand most of this messaging project is so I'll leave it up to you however it's best.

Changed in python-openstacksdk:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.