camel icon indicating copy to clipboard operation
camel copied to clipboard

Handling recursive structures

Open sarahzrf opened this issue 9 years ago • 5 comments

Certain kinds of recursive structures give me load errors. I did a little googling and found a solution in PyYAML (http://stackoverflow.com/a/29607120); does Camel support something like that? If not, would it be possible to patch support in?

sarahzrf avatar Feb 17 '16 14:02 sarahzrf

Actually, I'm working on trying to patch it in myself. It doesn't seem too hard so far...

sarahzrf avatar Feb 17 '16 16:02 sarahzrf

ok I figured out how to implement it, but... I've realized that, as I probably should've assumed that you already had, that PyYAML does not really mitigate the fact that loading circular structures is a hard problem... so never mind.

sarahzrf avatar Feb 18 '16 00:02 sarahzrf

For what it's worth, I still have my changes; if you think there'd be any worth in adding a finicky, confusingly-behaving cyclic-structure mode, I can reopen this.

sarahzrf avatar Feb 18 '16 01:02 sarahzrf

I'm not sure offhand how I'd tackle this, but it is an interesting problem, and I didn't know about that feature. I'll leave this open and take a closer look whenever I mess with camel next.

eevee avatar Feb 19 '16 06:02 eevee

The patch I wrote does work, it's just that its behavior is potentially confusing and bug-producing (which is more or less inherited from PyYAML). In particular, it forces you to worry about whether child values have been loaded. For example, this code might well be incorrect:

def _load_weakset():
    w = WeakSet()
    vals, version = yield w
    w.update(vals)

Since vals might not be fully loaded at the time update is called, it might later get appended to, and the new value wouldn't make it it into w.

sarahzrf avatar Feb 21 '16 01:02 sarahzrf