@@ -126,6 +126,16 @@ def test_merge_property(self):
126126 assert engine .merge_property ("foo" , "bar" ) == "foo"
127127 assert engine .merge_property (["foo" ], ["bar" ]) == ["foo" , "bar" ]
128128 assert engine .merge_property (None , ["bar" ]) == ["bar" ]
129+ # Test dict merging (for remote_ids)
130+ assert engine .merge_property ({}, {"wikidata" : "Q123" }) == {"wikidata" : "Q123" }
131+ assert engine .merge_property ({"viaf" : "123" }, {"wikidata" : "Q456" }) == {
132+ "viaf" : "123" ,
133+ "wikidata" : "Q456" ,
134+ }
135+ # When both have the same key, master's value should take preference
136+ assert engine .merge_property ({"wikidata" : "Q111" }, {"wikidata" : "Q222" }) == {
137+ "wikidata" : "Q111"
138+ }
129139
130140
131141def test_get_many ():
@@ -297,6 +307,30 @@ def test_work_authors(self):
297307 "authors" : [{"type" : "/type/author_role" , "author" : {"key" : "/authors/a" }}],
298308 }
299309
310+ def test_remote_ids_merge_wikidata_from_duplicate (self ):
311+ """Test that Wikidata ID from duplicate author is merged into master.
312+
313+ This reproduces the bug where remote_ids.wikidata was lost during merge.
314+ See: https://github.com/internetarchive/openlibrary/issues/11698
315+ """
316+ # Master author has no remote_ids (or empty dict)
317+ a = dict (TEST_AUTHORS .a )
318+
319+ # Duplicate author has a Wikidata ID
320+ b = dict (TEST_AUTHORS .b , remote_ids = {"wikidata" : "Q12345" })
321+
322+ c = dict (TEST_AUTHORS .c , remote_ids = {"wikidata" : "Q12346" , "viaf" : "123456" })
323+
324+ web .ctx .site .add ([a , b , c ])
325+ self .engine .merge ("/authors/a" , ["/authors/b" , "/authors/c" ])
326+
327+ # The Wikidata ID should be merged into the master
328+ master_remote_ids = dict (web .ctx .site .get ("/authors/a" ).get ('remote_ids' ))
329+ assert master_remote_ids == {
330+ "wikidata" : "Q12345" ,
331+ "viaf" : "123456" ,
332+ }, "remote_ids from duplicate should be merged into master"
333+
300334
301335def test_dicthash ():
302336 assert dicthash ({}) == dicthash ({})
0 commit comments