seperman/redisworks

can't assign redisworks results (for some object types) to redisworks

Opened this issue · 4 comments

# works
root.n1=1
root.n2=root.n1
root.a1="a"
root.a2=root.a1
root.l1=[1,2,3,4]
root.l2=root.l1

# fails with exception thrown
root.d1={"a":"b"}
root.d2=root.d1
root.t1=(1,2,3)
root.t2=root.t1

If you convert the LazyDot object back to a normal object before assigning, this works around the problem. If I add the following at the top of Root.__save_in_redis():

    if isinstance(value,LazyDot):
        value.__repr__()
        value=value.__deepcopy__(None) 

But I feel like its a deeper issue in LazyObject, which I'm having a really hard time understanding and debugging since overridding all the operators and the proxying of class attributes makes it behave in unexpected ways.

The exception seems to be an issue with the json dumping of the LazyDot object:

# fails with same exception
root.t1=(1,2,3)
json.dumps(root.t1)

So this comes back to the fact that all root attributes like root.t1 etc. are lazy dot objects as you have noticed. I have to make DotObject to get the value of another DotObject when it is assigned that DotObject. Regarding json serialization, I will take care of it. Thanks for reporting!

I think the json serialization problem is the cause of the assignment problem. (The exception thrown when doing the assignment from another DotObject comes from inside the json serialization)

Just came across this today and took a while to figure out what was going on. IMHO this should not error:

root.d1 = {"a": "b"}
root.d2 = root.d1

Unfortunately, root.d2 = dict(root.d1) doesn't work either. I had to resort to this:

root.d2 = {k: root.d1[k] for k in ['a']}

which obviously doesn't work unless you know the keys ahead of time.

This works

root.d2 = root.d1.__dict__['_registry'].evaluated_items['root.d1']