Attribute Form Combobox/Value-Relation-source based on virtual layer is not updated

I have a problem with a Combobox/Value Relation in QField, which obtains its key and values dynamically from a virtual or sql-query-layer. The source for the combobox is not refreshing as expected.

QGIS-Project with 2 layers:

  • Table with unique sample-IDs (1,2,3,4,…) : “sample_ids”
  • Point-layer with attribute-field to hold a sample-ID for the created points (sample-IDs must be unique): “point_layer”

These layers are packed in a Geopackage - and therefore are queryable via virutal layers or directly by a sql-query on the geopackage.
The QGIS-Project is exported for field-work with the QField-Sync-Plugin for QField.

The attribute-form of the point-layer has a combobox, to let the contributor select and assign a sample-ID. The sample-ID must be unique. Therefore a virtual layer is set up, which queries the possible sample-IDs from the table with sample-IDs and filters for the sample-IDs, which are not already used in the point-layer (this is done by a SQL-Query). This virtual layer is the data-source for the combobox - so it’s used as key/values in the widget type “Value Relation”.

SELECT sample_id FROM sample_ids LEFT JOIN point_layer ON sample_ids.sample_id = point_layer.sample_id WHERE point_layer.sample_id IS NULL
(sample_id is used as value and key in the Value Relation)

In QGIS (3.34) this works fine. The list of available sample-IDs in the combobox are always updated after a sample-ID is used and the next point is created.
In QField (3.4.4) the list of available sample-IDs (provided by the virtual layer) is NOT refreshed. So if I create the next sampling-point and fill the attribute-form, all the already used sample-IDs are still available for selection in the combobox. The strange thing is: the virtual layer with the available sample-IDs is updated immediatly after I saved a new sampling-point (I checked this by opening the attribute table of the virtual layer, after inserted a point in the point_layer) - but the combobox based on this virtual layer doesn’t. If I toggle off editing the point-layer, close QField-App and open it up again, the content of the combo box is updated. Of course it’s not a feasable practice to always close and open QField after inserting the next point.

Is this a bug, which should be listed under issues? Is there a workaround? Maybe someone has a hint or even a better approach to reach the goal. I searched a lot, but didn’t find another solution for example by using the constraints or filter options with its expression-capabilities in the attributes-form configuration instead of the virtual layer.


Imported from GitHub discussion by @dompec on 2024-11-04T20:20:16Z