Bug report #19050

QGIS saves integer field when I create a new real field through field calculator (Update field works as intended)

Added by Stefan Newluck over 6 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:Alessandro Pasotti
Category:Attribute table
Affected QGIS version:2.18.2 Regression?:Yes
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:Yes Copied to github as #:26880

Description

Problem:

When I create a new real field from within field calculator and calculate a decimal value, it is displayed correctly until I hit save. After save the field is saved as integer.

Please see the attached screenshot for an illustration.

What should happen:

The field should of course stay real.

Workaround:

Hit "Create field" and create a real field there. Then open field calculator and calculate decimal values into that field by updating it. Hit save and the field stays real.

Steps to reproduce:

0. Download this open data shapefile that I just use to confirm this bug: http://data.statistik.gv.at/data/OGDEXT_POLBEZ_1_STATISTIK_AUSTRIA_20180101.zip
1. Open the shapefile's attribute table and start editing
2. Create a dummy integer field
3. Open field calculator and calculate a new field with the ratio of the two integer fields
4. Save the table
5. The real field turns into integer.

QGIS_bug.PNG - TEST was created by field calculator. TEST2 was first created and then updated by field calculator. (14.7 KB) Stefan Newluck, 2018-05-28 10:44 PM

Associated revisions

Revision 033071ae
Added by Alessandro Pasotti over 6 years ago

Do not set min/max precision for int fields

Fixes #19050

QGIS saves integer field when I create a new real
field through field calculator (Update field works as intended)

backport required

Revision a7bc5365
Added by Alessandro Pasotti over 6 years ago

Do not set min/max precision for int fields

Fixes #19050

QGIS saves integer field when I create a new real
field through field calculator (Update field works as intended)

cherry-picked from master commit 033071a

History

#1 Updated by Alessandro Pasotti over 6 years ago

  • Assignee set to Alessandro Pasotti

I reproduced the issue, it looks like this is due to the "Output field length" value which is set to 0 by default when adding the field from "Create field" while the default is 10 when created from the calculator.

Can you please confirm my findings?

#2 Updated by Alessandro Pasotti over 6 years ago

  • Regression? changed from No to Yes
  • Resolution set to fixed/implemented
  • Pull Request or Patch supplied changed from No to Yes
  • Status changed from Open to In Progress

#3 Updated by Stefan Newluck over 6 years ago

Alessandro Pasotti wrote:

I reproduced the issue, it looks like this is due to the "Output field length" value which is set to 0 by default when adding the field from "Create field" while the default is 10 when created from the calculator.

Can you please confirm my findings?

Exactly this is the difference. If I set the "Output field length" to 0 in field calculator, decimal values are stored correctly upon save.

Thank you for looking into it! I'm looking forward to testing the fix. :)

#4 Updated by Anonymous over 6 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF