I have a script to generate map outputs using an APRX with predefined layouts. In the script, I am changing definition queries on multiple layers in layout's map frame, then change extent etc. and finally export a PNG. Legend items are strictly pre-defined as well, to prevent any overlapping with map frame for example.
I use this approach:
expression = "SOME SQL QUERY"
layer.definitionQuery = expression
I haven't run the script in a while, and now when I did so (after updating the APRX a bit in Pro 3.6), the layers where definition query was changed are automatically added to Legend element (all of them if there are multiple Legends in the layout) right after the code above runs. This is not desired in my case, as I mentioned above - the legend then stretches and overlaps map frame and other elements.
I can (and did) script a workaround, but is this expected behavior? I would prefer the layers not to be automatically added there.