scout_apm_python icon indicating copy to clipboard operation
scout_apm_python copied to clipboard

Support for psycopg Composed queries

Open pcrock-thmdo opened this issue 2 years ago • 5 comments

The Scout agent breaks when it tries to instrument raw queries in Django that use psycopg2's SQL string composition. Specifically, we get a TypeError: unhashable type: 'Composed' on this line of code:

https://github.com/scoutapp/scout_apm_python/blob/86d14920a59a7a3b5dfffe680586646ee29bdd7a/src/scout_apm/core/n_plus_one_tracker.py#L29

I created a workaround that converts the query to a raw string before executing it, however it involves getting a cursor and compiling the string before doing the actual query. That's more overhead than I would prefer, so it would be really nice if Scout were able to support Composed as well.

pcrock-thmdo avatar Jan 25 '23 10:01 pcrock-thmdo

Hi @pcrock-thmdo, thanks for opening the issue. Can you provide me with a reproducible example? That'll make the investigation a bit easier.

tim-schilling avatar Jan 25 '23 15:01 tim-schilling

Thanks for responding @tim-schilling, and sorry for the delay. Because of sickness, etc., I haven't had time to do this yet, but I'll get you an example soon.

pcrock-thmdo avatar Feb 06 '23 17:02 pcrock-thmdo

This reproduces the issue: https://github.com/pcrock-thmdo/scout-issue-749-poc

pcrock-thmdo avatar Feb 07 '23 18:02 pcrock-thmdo