Hi,
I simply decided to remove the constraint because it directly solved the problem, but I believe this is worth investigating, has constraints are a great tool on the field!
So, I did put a soft constraint on a field, and while it worked in itself, it created a weird behavior that render it useless.
My form is made of multiple relations with other tables (all postgres tables). In this case, I have 3 external tables (essentially 3 time the same structure) to separate vegetation strata, which are all called from a single “master form”.
What happens is that when I start to fill one of them on QField, everything is fine and the soft constraint throws exceptions when expected. But when I start filling my second strata/form, after the first entry, everything freezes. I tried several configurations of data entry, and the result is always the same within the 3 tables.
Here is the constrain in itself:
round(
(aggregate(
layer:='FormSect_SP_Herb',
aggregate:='sum',
expression:="Recouv_Abs_Num",
filter:="ID_MHH" = attribute(parent,'ID_MHH'))
+"Recouv_Abs_Num")
)<=100
Where:
FormSect_SP_Herb is the table
Recouv_Abs_Num is the field I want to calculate from
ID_MHH is a unique ID to the root form entry
In short, FormSect_SP_Herb contains data from several stations. So I have to filter the datas on the actual station UUID (ID_MHH). I then need to make sure that the total of all Recouv_Abs_Num for this ID_MHH is <= 100.
In itself, it works. But for a reason I don’t understand, it prevents me from adding entries in other tables (linked with a Relation). There is no actual link between these tables, so I don’t understand why the constraint would affect them, but not the rest of the form…
EDIT:
Actually, I realize I was testing too many things at the same time yesterday and misjudged; the problem seems to be related to the calculation itself, either when it is done in the default value calculation, or in the constraint. The two are based on the same principle. Everything runs smooth when I remove the calculation from both places. This problem is only present in QField, as I can add any number of entries in this project on QGIS. I’m currently using QGIS 3.22.4 and QField 2.0.14
You can find a test project exported for QField to test here:
To reproduce:
Create a new geometry (doesn't matter which)
From this window, add a "Evenement"
Scroll down to find "Formulaire MH", and add one
Swipe right to the 5th group I think, named "Strate Arborescente"
Add any number of entry there
Swipe right to either "Strate Arbustive" or "Strate Herbacée" and add 2 entries; the first will work, but the form will freeze if you try to add a second one
Imported from GitHub discussion by @OBVYamaska on 2022-04-06T16:52:55Z