<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Century Gothic";
        panose-1:2 11 5 2 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Century Gothic","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Hi List<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">I have a Python action that executes some SQL on selected features.  It works perfectly in my QGIS project.  If someone else opens the QGIS project they get an error from the action. 
 We both have the same connection to the database with the same name and with the same permissions on the tables.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Error on line 12 of script:<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:9.0pt;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;text-autospace:none">
<span style="font-size:10.0pt;font-family:"Courier New"">Traceback (most recent call last):<br>
  File "", line 12, in <br>
  File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 105, in run<br>
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)<br>
  File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 183, in runAlgorithm<br>
    raise QgsProcessingException(msg)<br>
_core.QgsProcessingException: There were errors executing the algorithm.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Courier New"">Python version:<br>
3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]<br>
<br>
QGIS version:<br>
3.4.5-Madeira 'Madeira', 89ee6f6e23</span><span style="font-family:"Century Gothic","sans-serif""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Python script. Line 12 is the processing.run() :<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">from qgis.PyQt import QtWidgets <br>
from qgis.core import Qgis <br>
from qgis.utils import iface <br>
import processing <br>
<br>
layer = QgsProject.instance().mapLayer('boq_locations_d3e2b1bd_e1fc_4ca8_83f2_e0bb738d2146') <br>
if layer.selectedFeatureCount(): <br>
    ids = layer.selectedFeatureIds() <br>
    for id in ids: <br>
        sql_query = "TRUNCATE parks.boc_task_to_add;" <br>
        print(sql_query) <br>
        processing.run("qgis:postgisexecutesql", {'DATABASE':editor@postgiswork', 'SQL':sql_query}) <br>
        sql_query = "INSERT INTO parks.boc_task_to_add (task_no, task_desc, task_unit, task_freq) SELECT t.task_no::numeric, t.task_desc, t.task_unit, t.task_freq FROM parks.boc_tasks t, parks.boq_locations s WHERE t.task_ref = s.task_ref AND s.gid = " + str(id) <br>
        print(sql_query) <br>
        processing.run("qgis:postgisexecutesql", {'DATABASE':'editor @postgiswork', 'SQL':sql_query}) <br>
        iface.messageBar().pushMessage("Done!", "Copied tasks for feature: " + str(id), level=Qgis.Info, duration=1) <br>
else: <br>
    iface.messageBar().pushMessage("Hey!", " Please select a polygon to copy tasks from first.", level=Qgis.Warning, duration=5)</span><span style="font-family:"Century Gothic","sans-serif""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Any idea why the action will work on my machine but not on someone else’s QGIS?  The only difference between machines is QGIS versions 3.4.4, 3.4.5 and 3.4.12.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif"">Ross<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Century Gothic","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB">Ross McDonald |
</span></b><span style="font-size:10.0pt;font-family:"Century Gothic","sans-serif";color:#4F6228;mso-fareast-language:EN-GB">Geo-evangelist | Angus Council, Digital Enablement and IT | Angus House, Orchardbank Business Park, Sylvie Way, Forfar DD8 1AT<b> |
 t: 01307 49 22 39<o:p></o:p></b></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div> </div>
<div>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 7.5pt; FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-font-size: 8.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="2">This message is strictly confidential. If you have received
 this in error, please inform the sender and remove it from your system. If received in error you may not copy, print, forward or use it or any attachment in any way. This message is not capable of creating a legal contract or a binding representation and does
 not represent the views of Angus Council. Emails may be monitored for security and network management reasons.<span style="mso-spacerun: yes">
</span>Messages containing inappropriate content may be intercepted. Angus Council does not accept any liability for any harm that may be caused to the recipient system or data on it by this message or any attachment.
</font></span></p>
</div>
</body>
</html>