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

Populating a column of type PostgreSQL array and list widget with an expression fails if "Apply default value on update" is enabled #46158

Closed
1 of 2 tasks
andreasneumann opened this issue Nov 22, 2021 · 5 comments · Fixed by #46172
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 Widgets

Comments

@andreasneumann
Copy link
Member

What is the bug or the crash?

The setup contains a PostgreSQL table where one or more columns are of type array (array of int4 or array of string).

CREATE TABLE test.test (
	t_id serial,
	geometrie geometry(multipolygon, 2056) NOT NULL,
	bfs_nr int4[],
	gb_nr varchar[],
	flurname varchar(255)
);

The associated widget should be a "list widget" and the list should be populated with an "overlay_intersects()" expression function as a default value:

image

image

The problem is that I cannot populate the list widget with the QGIS expression. The list always stays empty, even if I can see a correct preview that shows that the expression works.

I tried the following three expressions:

overlay_intersects(layer:='hoheitsgrenzen_gemeindegrenze', expression:=bfs_gemeindenummer)
'[' ||
array_to_string(
overlay_intersects(layer:='hoheitsgrenzen_gemeindegrenze', expression:=bfs_gemeindenummer),
',')
|| ']'
'{' ||
array_to_string(
overlay_intersects(layer:='hoheitsgrenzen_gemeindegrenze', expression:=bfs_gemeindenummer),
',')
|| '}'

Neither of the three expressions was able to populate the list widget, even if the preview always contained correct data.

Note: PostgreSQL arrays use curly brackets ( {} ) while QGIS arrays use square brackets ( [] ).

Steps to reproduce the issue

Dataset to test against (Geopackage) - for the overlay_intersects() expression:

hoheitsgrenzen_gemeindegrenze.gpkg.zip
.

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
QGIS version 3.23.0-Master QGIS code revision 1d1d59d
Qt version 5.12.8
Python version 3.8.10
GDAL/OGR version 3.3.1
PROJ version 8.1.0
EPSG Registry database version v10.027 (2021-06-17)
GEOS version 3.9.1-CAPI-1.14.2
SQLite version 3.31.1
Compiled against PDAL 2.0.1 Running against PDAL 2.3.0
PostgreSQL client version 13.3
SpatiaLite version 5.0.1
QWT version 6.1.4
QScintilla2 version 2.11.2
OS version Ubuntu 20.04.3 LTS
       
Active Python plugins
changeDataSource 3.1
trackable_project_files v1.2.2
QgisModelBaker v6.6.7
QuickWKT 3.1
DataPlotly 3.8.1
sagaprovider 2.12.99
processing 2.12.99
db_manager 0.1.20
grassprovider 2.12.99
solocator 1.4.1

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@andreasneumann andreasneumann added Bug Either a bug report, or a bug fix. Let's hope for the latter! Widgets Expressions Related to the QGIS expression engine or specific expression functions labels Nov 22, 2021
@m-kuhn m-kuhn self-assigned this Nov 22, 2021
@m-kuhn
Copy link
Member

m-kuhn commented Nov 22, 2021

Interestingly, this works for me with QGIS master, the postgis layer (created with the SQL in the issue description) and a simple scratch layer that corresponds to hoheitsgrenzen_gemeindegrenze.
This works if the data type of the field is int or string (with string the provider doesn't let me save the edits but the expression works and the widget is filled nonetheless).

Attached you find a gpkg project and a .qgs project (if you want to edit the XML before loading)
Can you test if this also works with your setup?

@gioman gioman added the Feedback Waiting on the submitter for answers label Nov 22, 2021
@andreasneumann
Copy link
Member Author

Confirmed - with your project it works, with my project not.

Now I have to dig in to find what the differences are ...

Let's keep the ticket open until it also works in my projects. I will add more info.

@andreasneumann
Copy link
Member Author

Ok - this is really weird.

If you rename the attribute "x" in layer "array_test" it starts failing. It would still display in the "Identify Results" panel correctly, but not in the list widgets.

Perhaps QGIS doesn't like it if both layers have the same attribute name?

@andreasneumann
Copy link
Member Author

Oh no - it is some completely different issue. Not the naming issue.

It starts failing if you enable the "Apply default value on update"

image

It has nothing to do with the column names.

@andreasneumann andreasneumann changed the title Populating a column of type PostgreSQL array and list widget with an expression Populating a column of type PostgreSQL array and list widget with an expression fails if "Apply default value on update" is enabled Nov 22, 2021
@andreasneumann andreasneumann removed the Feedback Waiting on the submitter for answers label Nov 22, 2021
m-kuhn added a commit to m-kuhn/QGIS that referenced this issue Nov 23, 2021
when they are created in the attribute dialog
Fixes qgis#46158
m-kuhn added a commit to m-kuhn/QGIS that referenced this issue Nov 23, 2021
when they are created in the attribute dialog
Fixes qgis#46158
@m-kuhn
Copy link
Member

m-kuhn commented Nov 23, 2021

Fix pending in #46172

FYI, the default value expression needs to return an array (not a string representation of an array), the fix is in the update of the default value on the attribute dialog, specific for "apply on update" and will work for any datatype that is not trivially convertible to string and back (like arrays here, but could also be geometry, date, ...).

m-kuhn added a commit to m-kuhn/QGIS that referenced this issue Nov 23, 2021
when they are created in the attribute dialog
Fixes qgis#46158
qgis-bot pushed a commit that referenced this issue Nov 24, 2021
when they are created in the attribute dialog
Fixes #46158
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 Widgets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants