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
257 stars 143 forks source link

[Bug]: n:m relation not shown correctly #4315

Open tbnobody opened 7 months ago

tbnobody commented 7 months ago

What is the bug? (in English)

A n:m relation is not shown correctly in the web frontend. It just shows the pivot table image

The table is defined as follows. image

image

The following exception is thrown by the lizmap server plugin (might be related to #4307):

Mar 19 21:54:54 boromir spawn-fcgi[49512]: 21:54:54 CRITICAL Lizmap[49512]: Critical exception:
Mar 19 21:54:54 boromir spawn-fcgi[49512]: 'Relation'
Mar 19 21:54:54 boromir spawn-fcgi[49512]: Traceback (most recent call last):
Mar 19 21:54:54 boromir spawn-fcgi[49512]:   File "/opt/qgis_server/plugins/lizmap_server/get_feature_info.py", line 178, in responseComplete
Mar 19 21:54:54 boromir spawn-fcgi[49512]:     features = self.feature_list_to_replace(cfg, project, relation_manager, xml)
Mar 19 21:54:54 boromir spawn-fcgi[49512]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 19 21:54:54 boromir spawn-fcgi[49512]:   File "/opt/qgis_server/plugins/lizmap_server/get_feature_info.py", line 121, in feature_list_to_replace
Mar 19 21:54:54 boromir spawn-fcgi[49512]:     html_content = Tooltip.create_popup_node_item_from_form(layer, root, 0, [], '', relation_manager)
Mar 19 21:54:54 boromir spawn-fcgi[49512]:                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 19 21:54:54 boromir spawn-fcgi[49512]:   File "/opt/qgis_server/plugins/lizmap_server/tooltip.py", line 180, in create_popup_node_item_from_form
Mar 19 21:54:54 boromir spawn-fcgi[49512]:     h = Tooltip.create_popup_node_item_from_form(layer, n, level, headers, html, relation_manager)
Mar 19 21:54:54 boromir spawn-fcgi[49512]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 19 21:54:54 boromir spawn-fcgi[49512]:   File "/opt/qgis_server/plugins/lizmap_server/tooltip.py", line 116, in create_popup_node_item_from_form
Mar 19 21:54:54 boromir spawn-fcgi[49512]:     relation = relation_manager.relation(widget_config['Relation'])
Mar 19 21:54:54 boromir spawn-fcgi[49512]:                                          ~~~~~~~~~~~~~^^^^^^^^^^^^
Mar 19 21:54:54 boromir spawn-fcgi[49512]: KeyError: 'Relation'

Therefore I changed the tooltip.py in line 114 (bad hack, I know)

            if widget_type == 'RelationReference':
                referenced_layer = None
                if widget_config.get('Relation', None) != None:
                    relation = relation_manager.relation(widget_config['Relation'])
                    referenced_layer = relation.referencedLayer()

Now i got the following log output:

Mar 19 22:08:45 boromir spawn-fcgi[50007]: Layer trail_supervisor_dbc88c91_e3ad_464a_8d4d_9ca12f752bad does not have a valid relation reference layer for field tail_id
Mar 19 22:08:45 boromir spawn-fcgi[50007]: Layer trail_supervisor_dbc88c91_e3ad_464a_8d4d_9ca12f752bad does not have a valid relation reference layer for field supervisor_id

Not sure why the relation is missing. The layer are shared via WFS: image

Steps to reproduce the issue

Also covered above...

Versions, safeguards, check summary etc

Versions :

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

Check Lizmap plugin

Operating system

Windows 11

Browsers

Chrome

Browsers version

Vivaldi 6.5.3206.53 (Stable channel) (32-Bit)

Relevant log output

No response

tbnobody commented 7 months ago

It seems to work now, but I had to add the primary id to all three layers in the attributes form editor (e.g. id): image