Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze when using aggregate in a virtual field #39366

Open
3nids opened this issue Oct 14, 2020 · 9 comments
Open

Freeze when using aggregate in a virtual field #39366

3nids opened this issue Oct 14, 2020 · 9 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions

Comments

@3nids
Copy link
Member

3nids commented Oct 14, 2020

Using a layer with 1 feature, the following expression: aggregate('test','sum',"HECTARES","TYPE"=attribute(@parent,'TYPE'))

using this as a label causes no issue
using it in virtual field leads to a freeze (see the stack trace)

it doesn't seem to be related to the backend (tested with PG and GPKG)

example project and data:
issue-aggregate-virtual.zip
see the expression used in labelling, try to use it as a virtual field

So far, it looks like an infinite recursion in the aggregate as it uses the parent feature.

Stack trace:
image

@3nids 3nids added Bug Either a bug report, or a bug fix. Let's hope for the latter! Won't fix By design, or won't be fixed for some other reason labels Oct 14, 2020
@3nids
Copy link
Member Author

3nids commented Oct 15, 2020

The solution is to use a with_variable:

with_variable('type_value', "TYPE", aggregate('test','sum',"HECTARES","TYPE"=@type_value))

@roya0045
Copy link
Contributor

What is the point of "TYPE"=attribute(@parent,'TYPE') anyway? IRL I don't see why anyone would compare a field value to itself.

@3nids
Copy link
Member Author

3nids commented Oct 16, 2020

This can be used for instance to calculate aggreagates on a rolling window (cumulative sum up to the feature for instance).

@roya0045
Copy link
Contributor

Ah you mean when you need to fix a variable to the feature of origin and let the other one be dynamic? This would make sense. This seems unintuitive with 'with_variable', and using 'attribute' is only a way to fetch the field in a dynamic way (at leas this is how I use it in my models).

I assume this is caused by the fact that you fix the variable outside of the scope are than check it when evaluating...

@Gustry Gustry removed the Won't fix By design, or won't be fixed for some other reason label Feb 8, 2021
@garci66
Copy link

garci66 commented May 12, 2021

I know the issue is wont_fix, but I am having a very similar issue without even using the @parent. Just using aggregate in the virtual field (my operation is count) is enough to hang the UI.

@garci66
Copy link

garci66 commented May 12, 2021

In my case, the "with_variable" still didnt solve it. In fact, also other functions, such as "count" in a virtual field caused qgis to crash each time I applied the changes.

@roya0045
Copy link
Contributor

We would need the data and expression/project if someone wants to investigate.

@garci66
Copy link

garci66 commented May 12, 2021

The following is the project file:
Herramienta de diseño.zip

then in the layer called NAPs I create a new virtual field (of type integer) and use the following formula:

with_variable('p_id_Acceso',"id_Acceso",
with_variable('p_s_distance',"s_distance" ,
	count('id',filter:="id_Acceso"=@p_id_Acceso and "s_distance"<@p_s_distance)))+1	

and as soon as I apply the changes it fails. If I create a calculated (non-virtual) field, it works fine.

I know here i am not using the aggregate function, but I was using the "count" workaround as an option to the following:

aggregate('NAPs','count','id',"id_Acceso"=attribute(@parent,'id_Acceso') and "s_distance"<attribute(@parent,'s_distance'))+1

(both the id_Acceso and s_distance are also virtual fields. Might be related to that?

@gioman gioman added the Expressions Related to the QGIS expression engine or specific expression functions label May 13, 2021
@Pedro-Murteira
Copy link

This issue is still valid on QGIS 3.22.3. (Windows 10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions
Projects
None yet
Development

No branches or pull requests

6 participants