Aggregate calculation makes QField freeze

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

OBVYamaska , please provide a test project so developers can investigate this. Thanks


Imported from GitHub comment by @nirvn on 2022-04-07T01:04:07Z

You can find a diminished version of my project here: Error

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 comment by @OBVYamaska on 2022-04-07T18:51:22Z

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


Imported from GitHub comment by @OBVYamaska on 2022-04-07T20:12:03Z

I can only confirm the issue really exists. The project is quite complex to navigate to, if you are able to create a much simpler project to reproduce the issue would be great.


Imported from GitHub comment by @suricactus on 2022-04-25T22:00:31Z

I will try to upload a simple project reproducing this later this week.


Imported from GitHub comment by @OBVYamaska on 2022-05-02T17:50:32Z

suricactus , you can find a lighter version of the project here.

The suggested workflow to reproduce the problem is:

  • Create a point; this will open a first form
  • In this first form, click on the black + button to create an Observation (Point); this will open a second form
  • In this second form, find the “Formulaire MH” , click on the black + button to create a entry in the form; this will open a third form
  • You will then have 3 tabs, all based on the same principle. Choose either one, and create a entry in it. It can be empty.
  • Then, choose any OTHER tab, and create an entry. This should work. However, if you try to create a second one in the same tab, all should freeze

The formula that seems to create the problem is located in any of the three corresponding tables:

  • FormSect_SP_Herb
  • FormSect_SP_Arbuste
  • FormSect_SP_Arbre

It’s the default value for the “Recouv_Rel_Num” field.

To keep the behavior pretty much the same as in my project, I need to have at least the Evenement and Form_MHH tables (second and third forms). If you find this project to be still to complex, I’ll try to make a new one from scratch, but I believe this one should be easier to navigate.


Imported from GitHub comment by @OBVYamaska on 2022-05-03T22:21:51Z