@@ -396,3 +396,62 @@ async def test_add_tag_to_node(self, client_with_dbt: AsyncClient) -> None:
396396 assert response .status_code == 200
397397 response_data = response .json ()
398398 assert response_data == []
399+
400+ @pytest .mark .asyncio
401+ async def test_tagging_node_with_same_tags_does_not_create_history (
402+ self ,
403+ client_with_dbt : AsyncClient ,
404+ ) -> None :
405+ """
406+ Test that tagging a node with the same tags doesn't create a new history event.
407+ """
408+ # Create tags
409+ await self .create_tag (client_with_dbt )
410+ await self .create_another_tag (client_with_dbt )
411+
412+ # Tag a node with two tags
413+ response = await client_with_dbt .post (
414+ "/nodes/default.items_sold_count/tags/?tag_names=sales_report&tag_names=reports" ,
415+ )
416+ assert response .status_code == 200
417+
418+ # Check history - should have one tag event
419+ response = await client_with_dbt .get (
420+ "/history?node=default.items_sold_count" ,
421+ )
422+ history = response .json ()
423+ tag_events = [h for h in history if h ["activity_type" ] == "tag" ]
424+ assert len (tag_events ) == 1
425+ assert tag_events [0 ]["details" ] == {"tags" : ["sales_report" , "reports" ]}
426+
427+ # Tag the same node with the same tags again (order may differ)
428+ response = await client_with_dbt .post (
429+ "/nodes/default.items_sold_count/tags/?tag_names=reports&tag_names=sales_report" ,
430+ )
431+ assert response .status_code == 200
432+
433+ # Check history again - should still have only one tag event (no new history)
434+ response = await client_with_dbt .get (
435+ "/history?node=default.items_sold_count" ,
436+ )
437+ history = response .json ()
438+ tag_events = [h for h in history if h ["activity_type" ] == "tag" ]
439+ assert len (tag_events ) == 1 , (
440+ "No new history event should be created when tags haven't changed"
441+ )
442+
443+ # Now actually change the tags - remove one
444+ response = await client_with_dbt .post (
445+ "/nodes/default.items_sold_count/tags/?tag_names=sales_report" ,
446+ )
447+ assert response .status_code == 200
448+
449+ # Check history - should now have two tag events
450+ response = await client_with_dbt .get (
451+ "/history?node=default.items_sold_count" ,
452+ )
453+ history = response .json ()
454+ tag_events = [h for h in history if h ["activity_type" ] == "tag" ]
455+ assert len (tag_events ) == 2 , (
456+ "A new history event should be created when tags are changed"
457+ )
0 commit comments