Hi List

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.

Error on line 12 of script:
Traceback (most recent call last):
  File "", line 12, in
  File 
"C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\general.py",
 line 105, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, 
context)
  File 
"C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\core\Processing.py",
 line 183, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.
Python version:
3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]

QGIS version:
3.4.5-Madeira 'Madeira', 89ee6f6e23

Python script. Line 12 is the processing.run() :

from qgis.PyQt import QtWidgets
from qgis.core import Qgis
from qgis.utils import iface
import processing

layer = 
QgsProject.instance().mapLayer('boq_locations_d3e2b1bd_e1fc_4ca8_83f2_e0bb738d2146')
if layer.selectedFeatureCount():
    ids = layer.selectedFeatureIds()
    for id in ids:
        sql_query = "TRUNCATE parks.boc_task_to_add;"
        print(sql_query)
        processing.run("qgis:postgisexecutesql", 
{'DATABASE':editor@postgiswork', 'SQL':sql_query})
        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)
        print(sql_query)
        processing.run("qgis:postgisexecutesql", {'DATABASE':'editor 
@postgiswork', 'SQL':sql_query})
        iface.messageBar().pushMessage("Done!", "Copied tasks for feature: " + 
str(id), level=Qgis.Info, duration=1)
else:
    iface.messageBar().pushMessage("Hey!", " Please select a polygon to copy 
tasks from first.", level=Qgis.Warning, duration=5)

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.

Thanks

Ross



Ross McDonald | Geo-evangelist | Angus Council, Digital Enablement and IT | 
Angus House, Orchardbank Business Park, Sylvie Way, Forfar DD8 1AT | t: 01307 
49 22 39


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. 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.
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to