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

Expression editor: syntax check fails if table is empty #37100

Closed
andreasneumann opened this issue Jun 10, 2020 · 3 comments · Fixed by #37139
Closed

Expression editor: syntax check fails if table is empty #37100

andreasneumann opened this issue Jun 10, 2020 · 3 comments · Fixed by #37139
Assignees
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 Regression Something which used to work, but doesn't anymore

Comments

@andreasneumann
Copy link
Member

Describe the bug
When the table is empty - naturally the preview fails - but the syntax check should not fail:
image

Table has at least one record (syntax check of the exact same expression as before is fine):
image

I would expect the syntax check to also work fine on an empty table.

QGIS and OS versions
Tested in QGIS master (3.13) on Linux Ubuntu 18.04

@andreasneumann andreasneumann added Expressions Related to the QGIS expression engine or specific expression functions Regression Something which used to work, but doesn't anymore Bug Either a bug report, or a bug fix. Let's hope for the latter! labels Jun 10, 2020
@3nids 3nids self-assigned this Jun 10, 2020
@3nids
Copy link
Member

3nids commented Jun 11, 2020

It seems than evaluating an expression with a feature only having its fields set leads to eval errors

layer = QgsVectorLayer('Polygon?crs:epsg=3879&field=test:text','test',"memory")
e = QgsExpression('"test"')
c = QgsExpressionContext()
f = QgsFeature(layer.fields())
c.setFeature(f)
e.evaluate(c)
e.hasEvalError()

=> True

Forcing it to be valid actually solves the issue.

f.setValid(True)
c.setFeature(f)
e.evaluate(c)
e.hasEvalError()

=> False

I am a bit skeptical on the raod to follow:

  1. change the evaluation to discard the validity flag and try to evaluate in any case
  2. change the feature picker so that it emits a valid feature instead of an invalid one.

Any opinion?

@m-kuhn
Copy link
Member

m-kuhn commented Jun 11, 2020

change the feature picker so that it emits a valid feature instead of an invalid one.

I would go for that one "mock a valid feature if we cannot find one in the layer"

3nids added a commit to 3nids/QGIS that referenced this issue Jun 11, 2020
and force it to be valid in the expression preview widget, so expression can be evaluated even when layer has no feature

fixes qgis#37100
@3nids
Copy link
Member

3nids commented Jun 11, 2020

here is a proposal where I force the feature to be valid: #37139

nyalldawson pushed a commit that referenced this issue Jun 11, 2020
and force it to be valid in the expression preview widget, so expression can be evaluated even when layer has no feature

fixes #37100
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 Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants