Skip to content

fix: normalize qgis_projects blob types around commit for QGIS compatibility#124

Draft
idshklein wants to merge 2 commits intokoordinates:mainfrom
idshklein:fix/qgis-projects-blob-commit-compatibility
Draft

fix: normalize qgis_projects blob types around commit for QGIS compatibility#124
idshklein wants to merge 2 commits intokoordinates:mainfrom
idshklein:fix/qgis-projects-blob-commit-compatibility

Conversation

@idshklein
Copy link
Copy Markdown

Problem

When a QGIS project is saved into a Kart-managed GeoPackage, QGIS writes qgis_projects.content as a text-encoded hex string and qgis_projects.metadata as plain text.

Kart's internal schema for qgis_projects declares both columns as �lob. When a user attempts to commit via the plugin, kart commit fails with:

\
Schema violation - values do not match schema
\\

Conversely, if the rows are converted to true blobs before the commit, QGIS can no longer open the project from the working-copy GeoPackage (\Unable to unzip file).

Fix

Three methods are added to Repository in kartapi.py:

Method Purpose
_gpkgHasQgisProjects(gpkg_path) Guards the normalization path – only activates when a qgis_projects table exists
_normalizeQgisProjectsForKart(gpkg_path) Converts content from text-hex → blob (unhex) and metadata from text → blob, just before kart commit
_restoreQgisProjectsForQgis(gpkg_path) Reverses the conversion in a inally block so QGIS can still open the project after commit

The round-trip is transparent to the user: the GPKG is left in the same QGIS-readable state it was in before the commit.

Scope

  • Only affects GeoPackage working copies (PostgreSQL is unchanged).
  • No-op when no qgis_projects table is present.
  • The inally block guarantees restoration even if the commit itself fails.

Testing

Manually verified end-to-end on Windows 11 / QGIS 3.38 / Kart 0.14:

  1. Open a Kart-managed GPKG project in QGIS → save → plugin commit → project still opens ✅
  2. kart log shows the new commit with updated qgis_projects ✅
  3. kart restore + reopen in QGIS works as expected ✅

…ompatibility

QGIS stores qgis_projects.content as text-encoded hex and qgis_projects.metadata
as plain text, but Kart's internal schema declares both columns as blob.  When a
user tries to commit, Kart raises:

  Schema violation - values do not match schema

This fix wraps Repository.commit() with two helpers:
  _normalizeQgisProjectsForKart  – converts text → blob/unhex just before kart commit
  _restoreQgisProjectsForQgis    – converts blob → text/hex in a finally block

so that (a) the commit succeeds and (b) QGIS can still open the project from the
working-copy GeoPackage without any user-visible disruption.

The normalization is only applied when the working copy is a GeoPackage (not
PostgreSQL) and only when a qgis_projects table is present.
…re loop

feature.fields().names() includes auto_int_pk (Kart's surrogate primary key
added to GeoPackage working copies) but the diff JSON props only contains the
actual dataset columns.  Iterating all field names and blindly indexing into
props crashes with KeyError: 'auto_int_pk'.

The idField value is already set explicitly on the line that follows the loop,
so missing fields can safely be skipped with a guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant