Skip to content

Commit

Permalink
Merge pull request #549 from opengisch/QF-2589-fix-apply-deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Mar 13, 2023
1 parent 986a2f1 commit 928eca9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
8 changes: 7 additions & 1 deletion docker-app/qfieldcloud/core/tests/test_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ def test_non_spatial_delta(self):
"STATUS_APPLIED",
self.user1.username,
],
[
"6c127828-b072-4939-a955-2018175748ac",
"STATUS_APPLIED",
self.user1.username,
],
[
"f326c3c1-138f-4261-9151-4946237ce714",
"STATUS_APPLIED",
Expand All @@ -727,7 +732,8 @@ def test_non_spatial_delta(self):
)

self.assertEqual(
self.get_file_contents(project, "nonspatial.csv"), b'fid,col1\n"1",qux\n'
self.get_file_contents(project, "nonspatial.csv"),
b'fid,col1\n"1",qux\n"2",newfeature\n',
)

def test_delta_pushed_after_job_triggered(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
}
}
},
{
"uuid": "6c127828-b072-4939-a955-2018175748ac",
"clientId": "cd517e24-a520-4021-8850-e5af70e3a612",
"exportId": "f70c7286-fcec-4dbe-85b5-63d4735dac47",
"localPk": "2",
"sourcePk": "",
"localLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c",
"sourceLayerId": "nonspatial_5b9be5d0_6faa_4c14_825d_7889615c842c",
"method": "create",
"new": {
"geometry": null,
"attributes": {
"fid": 2,
"col1": "newfeature"
}
}
},
{
"uuid": "f326c3c1-138f-4261-9151-4946237ce714",
"clientId": "cd517e24-a520-4021-8850-e5af70e3a612",
Expand Down
18 changes: 10 additions & 8 deletions docker-qgis/apply_deltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,20 @@ def get_geometry_from_delta(
geometry = None

if "geometry" in delta_feature:
wkt = delta_feature["geometry"].strip()

if not isinstance(wkt, str):
raise DeltaException("The provided geometry is not null or a WKT string.")

if len(wkt) == 0:
raise DeltaException("Empty WKT string!")

if delta_feature["geometry"] is None:
# create an invalid geometry to indicate that the geometry has been deleted
geometry = QgsGeometry()
else:
wkt = delta_feature["geometry"].strip()

if not isinstance(wkt, str):
raise DeltaException(
f"The provided geometry is of type {type(wkt)} which is neither null nor a WKT string."
)

if len(wkt) == 0:
raise DeltaException("Empty WKT string!")

wkt = wkt_nan_to_zero(wkt)
geometry = QgsGeometry.fromWkt(wkt)

Expand Down

0 comments on commit 928eca9

Please sign in to comment.