[PATCH RFC v2 02/25] review: do not clear fields a re-adding caller does not know

Christian Brauner <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
add_series_to_db()'s UPSERT arm writes pw_series_id and fingerprint
straight from the excluded row, so every re-add clears whatever the
caller did not happen to know.

The callers do not all know both.  The Patchwork tracker re-adds a series
to attach its pw id and has no fingerprint.  rescan_branches() replays a
branch and has neither.  A CLI re-track has the fingerprint and no pw id.
Each one dropped what the others had recorded, leaving a series that no
longer matched by content, or one that lost its Patchwork link.

Passing None means "not known here", not "clear it".  Use COALESCE.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 src/b4/review/tracking.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/b4/review/tracking.py b/src/b4/review/tracking.py
index a0c4ca4f..52b9a897 100644
--- a/src/b4/review/tracking.py
+++ b/src/b4/review/tracking.py
@@ -449,7 +449,15 @@ def add_series_to_db(
     added_at: Optional[str] = None,
     is_rethreaded: bool = False,
 ) -> int:
-    """Add a series to the tracking database. Returns the track_id."""
+    """Add a series to the tracking database. Returns the track_id.
+
+    On conflict the identity fields converge instead of overwriting: a
+    caller that does not know the Patchwork id or the fingerprint leaves
+    an existing one in place.  Re-adds come from callers that never
+    learned those fields -- the Patchwork tracker attaching its id,
+    rescan_branches replaying a branch -- and each used to wipe whatever
+    the others had recorded.
+    """
     if added_at is None:
         added_at = datetime.datetime.now(datetime.timezone.utc).isoformat()
     cursor = conn.execute(
@@ -466,8 +474,8 @@ def add_series_to_db(
             added_at = COALESCE(series.added_at, excluded.added_at),
             message_id = excluded.message_id,
             num_patches = excluded.num_patches,
-            pw_series_id = excluded.pw_series_id,
-            fingerprint = excluded.fingerprint,
+            pw_series_id = COALESCE(excluded.pw_series_id, series.pw_series_id),
+            fingerprint = COALESCE(excluded.fingerprint, series.fingerprint),
             is_rethreaded = excluded.is_rethreaded
         RETURNING track_id
     """,

-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.