Bug report #15935

"Default values" expression widget doesn't allow aggregate functions nor list layer fields

Added by Harrissou Santanna almost 8 years ago. Updated almost 8 years ago.

Status:Closed
Priority:Normal
Assignee:Nyall Dawson
Category:Edit widget
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:wontfix
Crashes QGIS or corrupts data:No Copied to github as #:23851

Description

Using the expression widget to set a "default value" for a field, I encounter some weird limitations:
- fields are not proposed in the "fields and values" list in the expression dialog: only NULL is shown
- trying to use aggregate functions returns an error : Cannot use aggregate function in this context

BUT
you can write in the textbox an expression like maximum("myfield") + 1 and it works.

A bug? (I try on a scratch layer)

History

#1 Updated by Nyall Dawson almost 8 years ago

  • Resolution set to wontfix
  • Status changed from Open to Closed

It's not possible to use other fields from the same layer in the default value expression. So an aggregate calculation from another layer would work, but not from the same layer.

#2 Updated by Harrissou Santanna almost 8 years ago

Then, it seems there's a bug in the implementation: the expression in my previous message (maximum("myfield") + 1) uses a field of the current layer, actually the field being "widgeted"; this successfully creates a serial field.
But i can also use expression like maximum("anotherfieldofthecurrentlayer")+1. The only limitation is that the expression can not be set within the expression builder but it works.
I'm on master 37c43df

Also available in: Atom PDF