qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.41k stars 2.98k forks source link

Unwanted unique constraint added when exporting to geopackage, if not null constraint is applied via default style. #58431

Open EVWK opened 1 month ago

EVWK commented 1 month ago

What is the bug or the crash?

When a layer with a default style is exported to a geodatabase, the "Unique" and "Enforce unique constraint" constraints get turned on in the form widget for all columns that have the "Not null" constraint applied in the default style.

Steps to reproduce the issue

1) Open a map layer, from a PostGIS geodatabase schema, in QGIS. 2) Open the Layer Properties wizard for your layer, and go to the Attributes Form tab. Set the dropdown at the top to "Drag and Drop Designer". 3) In the Available Widgets box, select one of the columns in your layer to open the widget settings. 4) In the Constraints tab, tick Not null. Leave Unique unticked. 5) Click "Apply". 5) Click the "Style" tab at the bottom of the window > "Save as Default" > Datasource Database. 6) Close the wizard window. 6) Remove the layer from your project. Then re-add it. The default style should load, and the constraints in the widgets will be set up correctly. 7) Open the Package layers tool from the Processing Toolbox. 8) Export your layer to a geopackage (choose a folder location), with "save layer styles into Geopackage" ticked 9) Open your new geopackage in QGIS, and check the constraints on the columns in the Attributes Form in the Layer Properties. You will find that, for any columns that had "Not null" constraint ticked, but not the unique constraint, they now have the "Unique" and "Enforce unique" constraints ticked as well. .... Note that if, after opening your map layer with the default style, you then reload the exact same style using the Style tab at the bottom of the Layer Properties window (Style > Load Style... > From Database (postgres) > choose your default style in the "Styles related to the layer" box) then exporting it to the geopackage works perfectly! Note also that in the example in the screenshot, the Not null comes from the database and is not enforced in the widget, but the same thing happens if it is only in the widget and if it is enforced.

NotNull_AndUniqe_Widget_Geopackage_layer NotNull_NotUnique_Widget_PostGIS_layer ... This is the log from the export to geopackage: QGIS version: 3.16.5-Hannover QGIS code revision: 58ba7c1ed6 Qt version: 5.11.2 GDAL version: 3.1.4 GEOS version: 3.8.1-CAPI-1.13.3 PROJ version: Rel. 6.3.2, May 1st, 2020 Processing algorithm… Algorithm 'Package layers' starting… Input parameters: { 'LAYERS' : ['dbname=\'bb_dev\' host=192.168.0.118 port=5432 sslmode=disable key=\'gid\' srid=27700 type=Point checkPrimaryKeyUnicity=\'1\' table=\"temp\".\"test_unique\" (geom)'], 'OUTPUT' : '//tsclient/P/LiveData/M1.1.19_DATA_MANAGEMENT/Temp_TestMergin/Test_unique_constraints.gpkg', 'OVERWRITE' : False, 'SAVE_STYLES' : True }

Packaging layer 1/1: test_unique Execution completed in 2.01 seconds Results: {'OUTPUT': '//tsclient/P/LiveData/M1.1.19_DATA_MANAGEMENT/Temp_TestMergin/Test_unique_constraints.gpkg', 'OUTPUT_LAYERS': ['//tsclient/P/LiveData/M1.1.19_DATA_MANAGEMENT/Temp_TestMergin/Test_unique_constraints.gpkg|layername=test_unique']}

Loading resulting layers Algorithm 'Package layers' finished

Versions

QGIS version 3.16.5-Hannover QGIS code revision 58ba7c1ed6 Compiled against Qt 5.11.2 Running against Qt 5.11.2 Compiled against GDAL/OGR 3.1.4 Running against GDAL/OGR 3.1.4 Compiled against GEOS 3.8.1-CAPI-1.13.3 Running against GEOS 3.8.1-CAPI-1.13.3 Compiled against SQLite 3.29.0 Running against SQLite 3.29.0 PostgreSQL Client Version 11.5 SpatiaLite Version 4.3.0 QWT Version 6.1.3 QScintilla2 Version 2.10.8 Compiled against PROJ 6.3.2 Running against PROJ Rel. 6.3.2, May 1st, 2020 OS Version Windows Server 2016 (10.0) Active python plugins GroupStats; plaingeometryeditor; quick_map_services; TomBio; db_manager; MetaSearch; processing

Supported QGIS version

New profile

Additional context

I am using the version of QGIS that my organisation allows, we don't have the latest one because it was causing problems for our system, I don't know the exact details.

I have NOT been able to use a new QGIS profile, I did try but it does not have any user permissions so I can't access my organisations' database to do anything.

EVWK commented 1 month ago

Update, this is happening to everyone in my organisation, so it isn't just my user profile, but it would be helpful to know if there is some setting that can be changed to mitigate it.