I am using a simple python script to add a definition query to all the layers in my map. The definition query appears to be successfully added to each layer, but isn't being applied until I open the definition query properties of each layer individually and then hit OK. Is there something else I should be adding to my script to actually apply the query to each layer? Here is my script:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Staking Job")[0]
for lyr in m.listLayers():
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = "st_workorder_ref_guid = '19205_SF'"
And here is a screenshot showing the contents when I open the query definition properties:

Again, the def query gets added, but doesn't actually get applied until I open the properties and hit OK without making any changes.
Additional info:
I tried the same thing in ArcMap (script was slightly different), and although it did update the definition query, I also got ArcMap Drawing Errors, with the message: "Underlying DBMS error [[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near ''.]". If I add the definition query manually, although it looks identical to the one created by the script, I don't get any error and the layer draws normally.