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

aggregates inside with_variable gives incorrect result #33382

Closed
puckipedia opened this issue Dec 13, 2019 · 6 comments · Fixed by #39391
Closed

aggregates inside with_variable gives incorrect result #33382

puckipedia opened this issue Dec 13, 2019 · 6 comments · Fixed by #39391
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

@puckipedia
Copy link

Describe the bug

When using any aggregate function (e.g. minimum) inside a with_variable, the result seems to be wrongly cached, even if it's not cachable.

How to Reproduce

  • Create a layer with an id column, which can contain any value (as long as it's unique per row)
  • Filter on "id" = with_variable('outer_id', "id", minimum("id", filter := "id" = @outer_id)) (guess who only just learned of @parent, lol)
  • Notice that, while the filter expression should be a noop, the only result is the first row.

QGIS and OS versions

QGIS version 3.10.0-A Coruña QGIS code branch Release QGIS code branch.3
Compiled against Qt 5.12.5 Running against Qt 5.12.5
Compiled against GDAL/OGR 3.0.1 Running against GDAL/OGR 3.0.1
Compiled against GEOS 3.7.3-CAPI-1.11.3 Running against GEOS 3.7.3-CAPI-1.11.3 b50468f
Compiled against SQLite 3.30.0 Running against SQLite 3.30.0
PostgreSQL Client Version 11.5 SpatiaLite Version 4.3.0a
QWT Version 6.1.2 QScintilla2 Version 2.11.2
Compiled against PROJ 6.1.1 Running against PROJ Rel. 6.1.1, July 1st, 2019
OS Version NixOS 20.03pre-git (Markhor)
Active python plugins pdokservicesplugin; db_manager; processing
@puckipedia puckipedia added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Dec 13, 2019
@gioman gioman added the Expressions Related to the QGIS expression engine or specific expression functions label Dec 13, 2019
@DelazJ
Copy link
Contributor

DelazJ commented Dec 14, 2019

Ah.... the combination would be the culprit...?
I was writing to the list last day because an expression i had, combining with_variable and aggregate, was outputting wrong result while I was pretty sure it was right. I'll then rewrite it the expanded way. Thanks.

(guess who only just learned of @parent, lol)

I had suggested to add it to the list of variables and not only inside examples to make it more visible but it did not get a positive reply, so we just add it in the user manual. I still think it's worth it.

@luipir
Copy link
Contributor

luipir commented Oct 15, 2020

I've the same problem and seems with_valiable is not expanded... I'm doing a query to an second layer, btw a simplified use case is updating a field in a layer getting a value from a second one basing a quey... e.g. in field calculator:

with_variable(
   'temp',
   "field name in first layer",
   aggregate(layer:='second layer name',
   	             aggregate:='min',
		     expression:="field name to get from second layer",
		     filter:="field name to check in the second layer"=@temp)
)

a simplified use case gives always wrong result and seems with_variable is not expanded (the same happen using eval)

with_variable(
	'temp',
	"field name in the first layer",
	aggregate(layer:='second layer name',
			aggregate:='max',
			expression:=@temp)
)

@luipir
Copy link
Contributor

luipir commented Oct 15, 2020

I'm using pre-release 3.16 master version 7216045

@3nids
Copy link
Member

3nids commented Oct 15, 2020

@luipir we were currently discussing the issue with @nirvn
a fix is on its way!

@luipir
Copy link
Contributor

luipir commented Oct 15, 2020

tnx @3nids building right now

@luipir
Copy link
Contributor

luipir commented Oct 15, 2020

@3nids in my case the PR fixes the issue.

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
5 participants