Give us a convenience method to get exchanges

Create issue
Issue #57 new
Niko Heeren created an issue

Hey. There is probably a good reason why this does not work as I would expect, but I would like to put it out here nevertheless.

I find it surprising that the following returns None:

activity = db.random()
activity.get('name'), activity.get(u'exchanges')

I find it even more surprising that activity.as_dict()['exchanges'] does not exist.

I am guessing the reason is that you do not want to load the data already at this stage. Also, I gather the intended way to do this is to iterate over activity.exchanges(). However, I sometimes want to manually duplicate & modify datasets from the database and the easiest way to do that is to get the exchanges dictionary and then do my changes on that one. In order to do that, I currently need to load the entire database and then look up the process in question.

It would be nice if there were a convenience method à la activity.exchanges_as_dict() for that. Unfortunately, I do not have the resources to create a PR the moment.

Comments (4)

  1. Chris Mutel repo owner

    This is a reasonable request, but a bit harder than it seems. The easiest way to do this would be to adapt some code from wurst, which does the same thing (get an activity with exchanges as dicts), but for an entire database.

    In the short term, I am probably going to focus any development time on getting the "next generation" ready. In the long term, I hope we can move away from this conceptual model of an exchange "belonging" to any given activity, and instead see these as separate objects that link two activities in a graph.

  2. Niko Heeren reporter

    OK. Wouldn't something like this work?

    def return_ex_dicts(self):
        return_me = []
        for exc in self.exchhanges():
        return return_me
  3. Chris Mutel repo owner

    Sure, but that only gets you the data loaded - you can't save that directly, there needs to be some massaging. If you look at the wurst code, you can see that this isn't too hard, but also not super simple.

  4. Niko Heeren reporter

    alright. so i guess the case is closed then and we consider including it for the next major release.

  5. Log in to comment