Json.loads causes unexpected results

For context, i have a class that is instantiated after json.loads is called. I started to get some strange results, so I added print statements inside the init to find out that it was getting called twice. Once by intention and once without intention. When i removed it from the code, it worked (albeit parsing errors followed)

In order to test this, I added a default argument for the class ‘called=true/false’ to test if I called it or not. i only have one instance of this class in my app, and purposely set it to ‘called=true’. with json.loads getting called before the class, it would get called once and work exactly as expected (parsing everything else) and then, for some strange reason, run once more with called=false (indicating that it ran without me calling it, weird).

When commenting out the json.loads that gets called before the class, the error goes away. the only thing i see is the ‘called=true’. This tells me without a doubt that json.loads is having a problem, forcing some rerun code or something. For me, that is unexpected behavior.

Could anyone explain this to me?

I can’t explain, but I can help you troubleshooting.

Try to put a raise Exception inside that call and run the app, so you see the traceback. Then put an if called: raise Exception and run again.

Now you have two tracebacks and see where the two calls originate.

(It would be great to simply print the traceback, rather than adding an intentional exception, but we can’t (yet)).

1 Like

Thank you for your reply.

I added the exception as suggested and it didn’t get me much closer.
However, I did find a way around it. If i do the ‘json.loads’ the moment the data is received (via websocket ‘on_message’ event).

Very unusual… at least it’s working now. I’m likely missing something somewhere with how json.loads is working when working with proxy objects.

Thanks again-