Bug report #21895

Default values and expression calculator not working together

Added by Jonathan Moules 7 months ago. Updated 7 months ago.

Status:Open
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:3.4.3 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:29710

Description

While trying to work around #21892 I encountered the following.

To replicate (in a GeoPackage - probably not format specific):
1) Create a new field of type Integer called whatever (_MY_FIELD here)
2) Use the Layer Properties -> Attributes Form to set a default value of 0 on _MY_FIELD, and tick the "Apply default on update" (this is the bug!)
3) Now, use expression calculator to UPDATE _MY_FIELD with any numerical value (fid will do).

Result = _MY_FIELD only has values of "0".

If you uncheck the "Apply default on update" then the update of the field will work as expected.

History

#1 Updated by Jürgen Fischer 7 months ago

  • Description updated (diff)

#2 Updated by Giovanni Manghi 7 months ago

  • Category changed from Field calculator to Vectors

#3 Updated by Giovanni Manghi 7 months ago

On the other hand the default does not do completely his job in other situations, like #21868

#4 Updated by Jonathan Moules 7 months ago

I ended up having to work around it with a logical if statement:

if("NEW_VALUE" is null, "NEW_VALUE", 0)

But only a workaround.

Also available in: Atom PDF