# Aggregate calculation makes QField freeze

**URL:** <https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908>\
**Category:** Ask the Community\
**Tags:** gh-import\
**Created:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908 "2025-05-14T03:14:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/1 "2025-05-14T03:14:24Z")

</div>

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:

```sql
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:

> **[Error](https://obvyamaska.sharepoint.com/:f:/s/OBVYamaska_Public/Ep8rdtiVFUVNungx6WsR320BvE2ei6JPHxlUrJim-k7YXg?e=in5gXB)**

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](https://github.com/opengisch/qfield/discussions/2712) by @OBVYamaska on 2022-04-06T16:52:55Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/2 "2025-05-14T03:14:26Z")

</div>

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

* * *

_Imported from [GitHub comment](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2520031) by @nirvn on 2022-04-07T01:04:07Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/3 "2025-05-14T03:14:27Z")

</div>

You can find a diminished version of my project here: [Error](https://obvyamaska.sharepoint.com/:f:/s/OBVYamaska_Public/Ep8rdtiVFUVNungx6WsR320BvE2ei6JPHxlUrJim-k7YXg?e=in5gXB)

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](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2526027) by @OBVYamaska on 2022-04-07T18:51:22Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/4 "2025-05-14T03:14:29Z")

</div>

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](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2526425) by @OBVYamaska on 2022-04-07T20:12:03Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/5 "2025-05-14T03:14:30Z")

</div>

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](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2634266) by @suricactus on 2022-04-25T22:00:31Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/6 "2025-05-14T03:14:31Z")

</div>

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

* * *

_Imported from [GitHub comment](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2675447) by @OBVYamaska on 2022-05-02T17:50:32Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 03:14 UTC](https://community.qfield.org/t/aggregate-calculation-makes-qfield-freeze/908/7 "2025-05-14T03:14:33Z")

</div>

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

> **[Error](https://obvyamaska.sharepoint.com/:f:/s/OBVYamaska_Public/EqR5jgZDZ09EtJ_8n6WmIwoBDNwTKFJyLqXPIGvzcBEA-g?e=SCqSRX)**

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](https://github.com/opengisch/QField/discussions/2712#discussioncomment-2683418) by @OBVYamaska on 2022-05-03T22:21:51Z_
