3liz / lizmap-web-client

Transfer a QGIS project on a server, Lizmap is providing the web interface to browse it
https://www.lizmap.com
Mozilla Public License 2.0
248 stars 141 forks source link

[Bug]: GetPrintAtlas does not work if id of feature is not a number #4534

Closed maxencelaurent closed 1 day ago

maxencelaurent commented 1 week ago

What is the bug? (in English)

Generating an atlas (GetPrintAltas) from a popup works fine if id of features is numeric.

Nonetheless, it doesn't work if the ID is of another type, especially uuid, which is pretty common when using postgis layers.

In https://github.com/3liz/lizmap-web-client/blob/283ec7cad7b9dd58d7ebf2cad2aa72027782a952/assets/src/components/FeatureToolbar.js#L648

The id should be escaped in some way.

 EXP_FILTER: `$id IN (${   typeof this._fid === 'string'  `'${this._fid.replace("'", "''")}' ` ? : this._fid    } )`, 

Not sure if the "$id IN (...)" syntax suggests this._fig may be a list of id (eg '1, 2, 3, 4' or [1, 2, 3, 4]) ?

It seems there is also some assumptions the ID is always numeric in the atlasprint plugin too.

Steps to reproduce the issue

  1. In qgis desktop, add a postgis layer which contains a geom and an UUID pkey
  2. in qgis project properties / qgisserver / WFS, make sure to publish the layer
  3. Create a layout
    1. toggle generate an atlas which cover this layer
  4. In lizmap plugin:
    1. make sure to check the popup checkbox for this layer
  5. Publish the project in LWC
  6. Click on any feature of the layer
  7. Click on the print icon

Versions, safeguards, check summary etc

Versions :

List of safeguards :
* Mode : normal * Allow parent folder : no * Prevent other drive : yes * Prevent PG service : no * Prevent PG Auth DB : yes * Force PG user&pass : yes * Prevent ECW : yes

Check Lizmap plugin

Operating system

Ubuntu 24.04

Browsers

Firefox

Browsers version

Not relevant but Firefox 127

Relevant log output

## HTTP 400 response:

"ATLAS - Error from the user while generating the PDF: Expression is invalid: \nsyntax error, unexpected NAME, expecting COMMA or ')'\nsyntax error, unexpected NAME, expecting end of file\nsyntax error, unexpected NAME, expecting end of file\nsyntax error, unexpected NAME, expecting end of file\nsyntax error, unexpected ')', expecting end of file"

Server logs

Qgis: AtlasPrint: Atlas print request error 400: ATLAS - Error from the user while generating the PDF: Expression is invalid:
syntax error, unexpected NAME, expecting COMMA or ')'
syntax error, unexpected NAME, expecting end of file
syntax error, unexpected NAME, expecting end of file
syntax error, unexpected NAME, expecting end of file
syntax error, unexpected ')', expecting end of file
Gustry commented 1 week ago

Lizmap plugin : 4.3.4

Can you upgrade your plugin ?

Nonetheless, it doesn't work if the ID is of another type, especially uuid, which is pretty common when using postgis layers.

I agree, but you are hitting a few issues on QGIS Server when PK is not integers. We do not recommend using strings as PK, it's written in the plugin when the CFG file is saved, you have some "important" rules in your table, please read the description of this error in the last column, in the tooltip.

maxencelaurent commented 1 week ago

My plugin is now up-to-date:

Versions :

List of safeguards :
* Mode : normal * Allow parent folder : no * Prevent other drive : yes * Prevent PG service : no * Prevent PG Auth DB : yes * Force PG user&pass : yes * Prevent ECW : yes

There is no "important" warning in the checks panel. I guess it's because my PK is of type text and the plugin only warns about int8 and varchar PKs.

Here are the corresponding rules in the help about checks tab:

(by the way, help about checks table is editable: Screencast from 2024-06-20 12-31-06.webm)

The description field reads

Primary key should be an integer. If not fixed, expect layer to have some issues with some tools in Lizmap Web Client: zoom to feature, filtering…

I do not experience any zoom-to-feature issue, neither from the data table nor the feature pop-up. On the other hand, filtering is, indeed, not working. Quoting string IDs when crafting the cFilter in attributeTable.js should fix this issue without breaking current behaviour.

https://github.com/3liz/lizmap-web-client/blob/283ec7cad7b9dd58d7ebf2cad2aa72027782a952/assets/src/legacy/attributeTable.js#L2797

Anyway, using integer PKs is not an option for us.

You mentioned QGIS server has some known issues with non-int PKs. I did not find much documentation about that. Do you have any idea where the problems are? I could take some time to investigate this.

Gustry commented 1 week ago

Thanks for your detailed bug report.

Quoting string IDs when crafting the cFilter in attributeTable.js should fix this issue without breaking current behaviour.

Can you provide a PR ?

Let me check for these fields.

maxencelaurent commented 1 week ago

I'll provide a PR by next days.

Is there any reason format and DPI options are disabled in the desktop plugin ? PNG/JPEG exports seem to work fine. image

Gustry commented 1 week ago

Is there any reason format and DPI options are disabled in the desktop plugin ?

Legacy because there isn't any menu to let the user choose the format when you print an atlas. So the solution would be to allow a single format to be checked for atlas ?

maxencelaurent commented 1 week ago

A complete solution would be to display a drop-down menu if many available formats are selected. The current html generation (in FeatureToolbar.js) would require a refactor to implement this. Especially to handle the dynamic field edition.

I will not address this issue in my PR. In a first step, I would simply rely on the default_format setting.