9

I am running a Windows Server 2012 server.

PostgreSQL 9.3.5, 64-bit

POSTGIS 2.1.3

QGIS Server 2.6.1-2

QGIS Desktop 2.8.3 and 2.12

I am using a Microsoft Surface Pro 4 tablet using QGIS Desktop 2.12 to edit some layers stored in the Postgresql database. The layers in the tablet are WFS layers served by QGIS Server.

When I toogle editing after inserting some data in the layer to force the data to be sent and stored in the server sometimes the update is not being done in the Database.

I can see that the POST http request arrives to the server ok, but sometimes I can't see a commit (update) in the database and some other times it works ok and does the commit.

In QGIS Server's logs I can see (I updated 3 features' data in QGIS Desktop):

//QGIS SERVER RECEIVED HTTP POST FROM QGIS DESKTOP

[4852][11:11:19] ********************new request*************** [4852][11:11:19] remote ip: 192.168.144.20 [4852][11:11:19] CONTENT_TYPE: text/xml [4852][11:11:19] HTTP_USER_AGENT: Mozilla/5.0 QGIS/2.8.2-Wien [4852][11:11:19] MAP:D:\OSGeo4W\apps\qgis\bin\alumbrado\alumbrado.qgs
[4852][11:11:19] REQUEST:Transaction
[4852][11:11:19] REQUEST_BODY:<Transaction xmlns="http://www.opengis.net/wfs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0"
service="WFS" xsi:schemaLocation="http://www.qgis.org/gml
http://eudala2.getxo.net/qgis/qgis_mapserv.fcgi.exe?map=D:\OSGeo4W\apps\qgis\bin\alumbrado\alumbrado.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=getxo_alumbrado_arquetas_registros_cajas&amp;SRSNAME=EPSG:23030"
xmlns:gml="http://www.opengis.net/gml"><Update
xmlns="http://www.opengis.net/wfs"
typeName="getxo_alumbrado_arquetas_registros_cajas"><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">id_modelo</Name><Value
xmlns="http://www.opengis.net/wfs">0</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">alumbrado</Name><Value
xmlns="http://www.opengis.net/wfs">t</Value></Property><Filter
xmlns="http://www.opengis.net/ogc"><FeatureId
xmlns="http://www.opengis.net/ogc"
fid="getxo_alumbrado_arquetas_registros_cajas.3"/></Filter></Update><Update
xmlns="http://www.opengis.net/wfs"
typeName="getxo_alumbrado_arquetas_registros_cajas"><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">id_modelo</Name><Value
xmlns="http://www.opengis.net/wfs">0</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">alumbrado</Name><Value
xmlns="http://www.opengis.net/wfs">t</Value></Property><Filter
xmlns="http://www.opengis.net/ogc"><FeatureId
xmlns="http://www.opengis.net/ogc"
fid="getxo_alumbrado_arquetas_registros_cajas.4"/></Filter></Update><Update
xmlns="http://www.opengis.net/wfs"
typeName="getxo_alumbrado_arquetas_registros_cajas"><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">tipo</Name><Value
xmlns="http://www.opengis.net/wfs">A</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">tipo_tapa</Name><Value
xmlns="http://www.opengis.net/wfs">B</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">estado</Name><Value
xmlns="http://www.opengis.net/wfs">D</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">p_tierra_tipo_electrodo_tierra</Name><Value
xmlns="http://www.opengis.net/wfs">O</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">p_tierra_tipo_union_electrodo_tierra</Name><Value
xmlns="http://www.opengis.net/wfs">N</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">p_tierra_estado_union_tierra</Name><Value
xmlns="http://www.opengis.net/wfs">D</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">tipo_intervencion</Name><Value
xmlns="http://www.opengis.net/wfs">OTR</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">m_codcalle</Name><Value
xmlns="http://www.opengis.net/wfs">20</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">id_modelo</Name><Value
xmlns="http://www.opengis.net/wfs">0</Value></Property><Property
xmlns="http://www.opengis.net/wfs"><Name
xmlns="http://www.opengis.net/wfs">alumbrado</Name><Value
xmlns="http://www.opengis.net/wfs">t</Value></Property><Filter
xmlns="http://www.opengis.net/ogc"><FeatureId
xmlns="http://www.opengis.net/ogc"
fid="getxo_alumbrado_arquetas_registros_cajas.5"/></Filter></Update></Transaction>
[4852][11:11:19] SERVICE:WFS
[4852][11:11:19] SRSNAME:EPSG:23030
[4852][11:11:19] VERSION:1.0.0
[4852][11:11:22] Request finished in 2977 ms

Ok, when I look into PostgreSQL logs I can see that the update has a WHERE NULL clause, which updates nothing..

//POSTGRESQL UPDATE QUERIES
2016-01-29 11:11:22 CET LOG:  00000: sentencia: UPDATE "public"."getxo_alumbrado_arquetas_registros_cajas" SET "id_modelo"=0,"alumbrado"='t' WHERE NULL
2016-01-29 11:11:22 CET UBICACIÓN:  exec_simple_query, src\backend\tcop\postgres.c:890
2016-01-29 11:11:22 CET LOG:  00000: sentencia: UPDATE "public"."getxo_alumbrado_arquetas_registros_cajas" SET "id_modelo"=0,"alumbrado"='t' WHERE NULL
2016-01-29 11:11:22 CET UBICACIÓN:  exec_simple_query, src\backend\tcop\postgres.c:890
2016-01-29 11:11:22 CET LOG:  00000: sentencia: UPDATE "public"."getxo_alumbrado_arquetas_registros_cajas" SET "tipo"='A',"tipo_tapa"='B',"estado"='D',"p_tierra_tipo_electrodo_tierra"='O',"p_tierra_tipo_union_electrodo_tierra"='N',"p_tierra_estado_union_tierra"='D',"tipo_intervencion"='OTR',"m_codcalle"='20',"id_modelo"=0,"alumbrado"='t'
WHERE NULL

I can see in the POST data that QGIS Server knows which feature needs to be updated using de internal "fid" number. My layer, on the other hand, has "id" field as primary key. Somewhere when it does the mapping from QGIS internal fid to my layer's id it's getting lost and adds WHERE null to the query instead of adding where id=1510.

The funny thing is that they have been working for 40 days and hey only got this problem once, but since last week they have had this problem every day...Since then sometimes works and sometimes not. I resend the POST http request from client ysing Fiddles proxy and the same HTTP post sometimes works and other times don't.

I tested it in QGIS Desktop 2.8, 2.10 and 2.12 and happens in all of them (QGIS Server is 2.6.1 I think). I also tested it with different layers with same result.

I don't know if there is a bug or there is some kind of config to the layer I am not doing properly in server...


UPDATE 03/03/2016

I updated to QGIS Server and QGIS Desktop to 2.12.3 both and the problem continues.

After many days of tests I finally found when the issue occurs. I happens when I save edits of the layer in QGIS (via WFS-T) and at the same time a Lizmap Map is being loaded by another user. Lizmap also uses qgis-server.

Looks like when loading a map, Lizmap makes the server busy and when a WFS-T update request is recived, QGIS Server is not capable of building the UPDATE SQL query correctly.Example:

If there is a Lizmap loading at the time the WFS-T post is received, the PostgreSQL query generated in qgis-server is:

2016-03-03 11:47:30 CET LOG:  00000: sentencia: UPDATE "public"."getxo_alumbrado_tendido_canalizacion" SET "diametro"='22' WHERE NULL

On the other hand, if qgis-server is not serving data to a loading Lizmap when the WFS-T arrives, the PostgreSQL query generated is:

2016-03-03 11:46:21 CET LOG:  00000: sentencia: UPDATE "public"."getxo_alumbrado_tendido_canalizacion" SET "diametro"='111' WHERE "id"::text='1' 

Note the diference in the where clause. The first one it does nothing. The second one works ok.

I don't know if I can tune Apache or any config files for qgis-server to fix this issue.

I tried giving much more hardware to the server (4 cores and 16 GB RAM) with no chnage.


I am making all the software updates using OSGEO4W. Ia read somewhere that Apache and PHP packages have not been updated for years. I'll try to update them manually and check that the apache or php version is not the cause of the problem.


UPDATE 16/03/2016

I updated Apache and PHP packages and the problem continues. After several tests I found that if I save edition changes (via WFS) while I am loading a Lizmap Map, the saving fails, but some other times keep failing although there is no Lizmap loading ( on lower volume ). It is a problem in QGIS Server (qgis_mapserv.fcgi.exe).

  • Can you show QGIS server logs when it works? I'm assuming they look the same, but we need to confirm that assumption. – alexGIS Mar 20 '16 at 21:40
  • @alexGIS Yes they are the same. I have written an answer with the solution to the problem. Thanks for your help! – Egidi Mar 21 '16 at 9:19
7

Finally, Matthias Kuhn, one of the developers of QGIS gave me the key.

The WHERE clause is built checking the type of the primary key of the table. It should be an Integer and in some of my tables I saw that the type was Numeric(8,0).

Those tables and primary keys were created by a third-party app some time ago.

I changed the type to Integer and all the tests I have made since then have worked (I have made more than 100 edition tests via WFS, enough in my opinion to conclude that the problem have been solved)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.