From 19a9010aa7b4e5b8df13f295db6d2fbe4b85c589 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 19 Jul 2021 22:07:41 +0200 Subject: [PATCH] Fix for OSM objects with multiple geometry --- web_view.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/web_view.py b/web_view.py index fb3e7c4..96b9cb0 100755 --- a/web_view.py +++ b/web_view.py @@ -3,6 +3,7 @@ from flask import (Flask, render_template, request, jsonify, redirect, url_for, g, flash, session, Response, stream_with_context) from sqlalchemy import func +from sqlalchemy.sql.expression import update from matcher import (nominatim, model, database, commons, wikidata, wikidata_api, osm_oauth, edit, mail, api) from matcher.data import property_map @@ -578,10 +579,12 @@ def process_edit(changeset_id, e): existing = root.find('.//tag[@k="wikidata"]') if e["op"] == "add" and existing is not None: return "already_added" - if e["op"] == "remove" and existing is None: - return "already_removed" + if e["op"] == "remove": + if existing is None: + return "already_removed" + if existing.get("v") != qid: + return "different_qid" - root = etree.fromstring(r.content) root[0].set("changeset", str(changeset_id)) if e["op"] == "add": tag = etree.Element("tag", k="wikidata", v=qid) @@ -604,8 +607,18 @@ def process_edit(changeset_id, e): if not success: return "element-error" - osm.tags["wikidata"] = qid - flag_modified(osm, "tags") + new_tags = dict(osm.tags) + if e["op"] == "add": + new_tags["wikidata"] = qid + if e["op"] == "remove": + del new_tags["wikidata"] + + cls = type(osm) + database.session.execute( + update(cls). + where(cls.src_id == osm.src_id). + values(tags=new_tags) + ) db_edit = model.ChangesetEdit( changeset_id=changeset_id,