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

Unable to overwrite the default style of a geopackage layer #42811

Closed
SrNetoChan opened this issue Apr 15, 2021 · 6 comments · Fixed by #45313
Closed

Unable to overwrite the default style of a geopackage layer #42811

SrNetoChan opened this issue Apr 15, 2021 · 6 comments · Fixed by #45313
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Symbology Related to vector layer symbology or renderers

Comments

@SrNetoChan
Copy link
Member

Describe the bug

Using a layer from a geopackage, you can define a default style and save it in the data source. Nevertheless, if a layer already has a default style, replacing it by trying to save a new default won't work.

How to Reproduce

  1. Load a layer from a geopackage source
  2. Set some easy to recognize style
  3. In properties or the styling panel, click on save as default. Save it in the Data source.
  4. Remove the layer and load it again. --> The default style should show up correctly
  5. Change the style of the layer again
  6. repeat step 3
  7. A message asks if you want to overwrite the existing style. Say yes.

If you reload the layer, the old style will be loaded, not the new one. Furthermore, if you check the messages panel, you will notice and 2021-04-15T11:26:22 WARNING Error updating style in the general panel.

QGIS and OS versions

QGIS version 3.16.5-Hannover QGIS code revision 58ba7c1
Compiled against Qt 5.9.5 Running against Qt 5.9.5
Compiled against GDAL/OGR 2.2.3 Running against GDAL/OGR 2.2.3
Compiled against GEOS 3.6.2-CAPI-1.10.2 Running against GEOS 3.7.1-CAPI-1.11.1 27a5e771
Compiled against SQLite 3.22.0 Running against SQLite 3.22.0
PostgreSQL Client Version 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1) SpatiaLite Version 4.3.0a
QWT Version 6.1.3 QScintilla2 Version 2.10.2
PROJ.4 Version 493
OS Version Ubuntu 18.04.5 LTS
Active python plugins splitmultipart; qgis2web; coretests; latlontools; qfieldsync; EditorMetadadosSNIMar; layout_loader; Qgis2threejs; changeDataSource; qconsolidate; ForestMetrixTools; QuickWKT; socarto_recart_tools; recartDGT; SpreadsheetLayers; geolayer_recart_tools; qgistester; nominatim_locator_filter; QuickOSM; SRTM-Downloader; DataPlotly; plugin_reloader; IPyConsole; Plugin; lizmap; EditorMetadadosMarswInforbiomares; profiletool; GlobeBuilder; db_manager; processing

Also tested on Windows 10 with the same results.

Additional context

@SrNetoChan SrNetoChan added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Apr 15, 2021
@gioman gioman added the Symbology Related to vector layer symbology or renderers label Apr 15, 2021
@gioman
Copy link
Contributor

gioman commented Apr 15, 2021

Confirmed also on master.

@nyalldawson nyalldawson self-assigned this May 24, 2021
@nyalldawson
Copy link
Collaborator

@rouault if you have some qgis bug fixing time left do you mind looking at this one? Somehow the database is remaining locked after the first "save as default style" action, so subsequent ones made after the layer is unloaded and reloaded fail. But I'm unable to debug why the locking is being released here...

@rouault
Copy link
Contributor

rouault commented May 24, 2021

I tried to reproduce the issue, but everything works fine for me. However could you try the following patch ?

diff --git a/src/core/providers/ogr/qgsogrprovider.cpp b/src/core/providers/ogr/qgsogrprovider.cpp
index fc10906cc6..c7209dcef7 100644
--- a/src/core/providers/ogr/qgsogrprovider.cpp
+++ b/src/core/providers/ogr/qgsogrprovider.cpp
@@ -6993,6 +6993,7 @@ bool QgsOgrProviderMetadata::saveStyle(
   OGR_L_SetAttributeFilter( hLayer, checkQuery.toUtf8().constData() );
   OGR_L_ResetReading( hLayer );
   gdal::ogr_feature_unique_ptr hFeature( OGR_L_GetNextFeature( hLayer ) );
+  OGR_L_ResetReading( hLayer );
   bool bNew = true;
 
   if ( hFeature )

@nyalldawson
Copy link
Collaborator

@rouault
no luck unfortunately. Here's how I can reproduce it:

  1. load a gpkg with one layer (point layer), style with some color
  2. save the style as default from layer properties -> style button -> save as default -> datasource database
  3. close the project
  4. add the gpkg back to qgis (eg via drag and drop from file manager)
  5. default style is restored. change the symbol color
  6. try to save over the default style by repeating step 2

@rouault
Copy link
Contributor

rouault commented May 25, 2021

no luck unfortunately. Here's how I can reproduce it:

hum, still no issue for me when following your procedure... Can you try the following patch (potentially combined with my initial one) ?

diff --git a/src/core/providers/ogr/qgsogrprovider.cpp b/src/core/providers/ogr/qgsogrprovider.cpp
index 2f69c074b3..1124849217 100644
--- a/src/core/providers/ogr/qgsogrprovider.cpp
+++ b/src/core/providers/ogr/qgsogrprovider.cpp
@@ -7211,6 +7211,7 @@ QString QgsOgrProviderMetadata::loadStyle( const QString &uri, QString &errCause
 
     }
   }
+  OGR_L_ResetReading( hLayer );
 
   return styleQML;
 }
@@ -7384,6 +7385,7 @@ QString QgsOgrProviderMetadata::getStyleById( const QString &uri, QString styleI
   QString styleQML( QString::fromUtf8(
                       OGR_F_GetFieldAsString( hFeature.get(),
                           OGR_FD_GetFieldIndex( hLayerDefn, "styleQML" ) ) ) );
+  OGR_L_ResetReading( hLayer );
 
   return styleQML;
 }

@SrNetoChan
Copy link
Member Author

Thanks @nyalldawson and @rouault

espinafre pushed a commit to espinafre/QGIS that referenced this issue Sep 29, 2021
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue Oct 5, 2021
Credit to @rouault for the fix!

Fixes qgis#42811

(cherry picked from commit eef6939)
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue Oct 5, 2021
Credit to @rouault for the fix!

Fixes qgis#42811

(cherry picked from commit eef6939)
nyalldawson added a commit that referenced this issue Oct 5, 2021
Credit to @rouault for the fix!

Fixes #42811

(cherry picked from commit eef6939)
nyalldawson added a commit that referenced this issue Nov 1, 2021
Credit to @rouault for the fix!

Fixes #42811

(cherry picked from commit eef6939)
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! Symbology Related to vector layer symbology or renderers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants