@@ -266,3 +266,46 @@ def test_pattern_reapplication_does_not_duplicate_delta_urls(self):
266
266
# Ensure no new `DeltaUrl` is created after reapplying the pattern
267
267
pattern .apply ()
268
268
assert DeltaUrl .objects .filter (url = curated_url .url ).count () == 0
269
+
270
+ @pytest .mark .django_db
271
+ def test_title_pattern_error_updates (self ):
272
+ """
273
+ Test that when a more specific pattern creates an error,
274
+ it updates rather than duplicates the error record.
275
+ """
276
+ # Create a collection and URL
277
+ collection = CollectionFactory ()
278
+ url = DeltaUrlFactory (
279
+ collection = collection , url = "https://example.com/docs/specific/item.html" , scraped_title = "Original Title"
280
+ )
281
+
282
+ # Create a general pattern first
283
+ general_pattern = DeltaTitlePattern .objects .create (
284
+ collection = collection ,
285
+ match_pattern = "*docs*" ,
286
+ # Use a different error-causing pattern
287
+ title_pattern = "{invalid}" , # Invalid variable name will cause error
288
+ match_pattern_type = 2 ,
289
+ )
290
+
291
+ # Verify initial error state
292
+ error = url .deltaresolvedtitleerror
293
+ assert error .title_pattern == general_pattern
294
+ assert "Variable 'invalid' not allowed in f-string pattern" in error .error_string
295
+
296
+ # Create a more specific pattern
297
+ specific_pattern = DeltaTitlePattern .objects .create (
298
+ collection = collection ,
299
+ match_pattern = "*docs/specific*" ,
300
+ # Different invalid variable
301
+ title_pattern = "{another_invalid}" ,
302
+ match_pattern_type = 2 ,
303
+ )
304
+
305
+ # Error should now be from specific pattern
306
+ error = url .deltaresolvedtitleerror # Should still only be one
307
+ assert error .title_pattern == specific_pattern
308
+ assert "Variable 'another_invalid' not allowed in f-string pattern" in error .error_string
309
+
310
+ # Verify we still only have one error record
311
+ assert DeltaResolvedTitleError .objects .filter (delta_url = url ).count () == 1
0 commit comments