Bug report #12257

Cannot create virtual field with delimited text layer

Added by Chris Crook about 9 years ago. Updated almost 9 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Field calculator
Affected QGIS version:2.8.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:20442

Description

When trying to add a field to a delimited text layer the Field Calculator UI does not enable the Output field type, width, and precision fields. This makes it impossible to define a valid field. So when OK is clicked, it is blocked with a message "Could not add the new field to the provider".

Steps to reproduce:

  • Open a valid CSV file in QGIS
    (eg
    id,lon,lat
    1,170.0,-45.0
    )
  • open the attribute table on the new layer
  • open the field calculator dialog
  • enter output field name "answer"
  • enter expression "42"
  • click OK.

Notes 1: It is possible to add a virtual field via python, ie

from PyQt4.QtCore import *
iface.mapCanvas().currentLayer().addExpressionField('42',QgsField("answer",QVariant.Int))

Notes 2: The UI should not enable the OK button if a valid field type is not selected

Associated revisions

Revision 9c2f5725
Added by Chris Crook about 9 years ago

Fix #12257 - allow creation of expression field on delimited text layer

Revision 5f1ed358
Added by Nathan Woodrow almost 9 years ago

Merge pull request #1932 from ccrook/Field_calculator_expression_fix

Fix #12257 - allow creation of expression field on delimited text layer

History

#1 Updated by Chris Crook about 9 years ago

Note: The issue comes from the logic used to identify when the calculator should create a virtual field. In this case despite the fact that the virtual field check box is checked (and not enabled), there is a second condition, on the new field checkbox, which is not met. Instead the calculator tries to create a provider field and fails.

The issue with no field data type being selectable is separate and relates to the delimited text provider. This is addressed in pull request #1931, which I have merged into master. If the other issue with the field calculator gets fixed I'd appreciate if it and #1931 could be backported to 2.8.1.

#2 Updated by Chris Crook about 9 years ago

I've submitted a fix (PR 1932) which addresses this

#3 Updated by Nathan Woodrow almost 9 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF