From 17b0a242576b17522542b6f8de3ff70566cf188a Mon Sep 17 00:00:00 2001 From: KaifAhmad1 Date: Wed, 18 Feb 2026 00:48:12 +0530 Subject: [PATCH] Log legacy policy constraint drop failures --- semantica/context/graph_schema.py | 7 +++++-- tests/context/test_graph_schema_logging.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/context/test_graph_schema_logging.py diff --git a/semantica/context/graph_schema.py b/semantica/context/graph_schema.py index d2e6406b..6b46e642 100644 --- a/semantica/context/graph_schema.py +++ b/semantica/context/graph_schema.py @@ -66,8 +66,11 @@ def create_decision_constraints(graph_store: GraphStore) -> None: try: # Drop legacy constraint when possible so versioned policies can coexist. graph_store.execute_query("DROP CONSTRAINT policy_id_unique IF EXISTS") - except Exception: - pass + except Exception as e: + get_logger(__name__).warning( + "Failed to drop legacy policy_id_unique constraint before policy " + f"versioning migration: {e}" + ) try: graph_store.execute_query( diff --git a/tests/context/test_graph_schema_logging.py b/tests/context/test_graph_schema_logging.py new file mode 100644 index 00000000..c22e0391 --- /dev/null +++ b/tests/context/test_graph_schema_logging.py @@ -0,0 +1,22 @@ +"""Regression tests for graph schema migration logging behavior.""" + +import logging +from unittest.mock import Mock + +from semantica.context.graph_schema import create_decision_constraints + + +def test_create_decision_constraints_logs_legacy_drop_failure(caplog): + graph_store = Mock() + + def _execute_query(query, *args, **kwargs): + if "DROP CONSTRAINT policy_id_unique IF EXISTS" in query: + raise RuntimeError("drop failed") + return {"records": []} + + graph_store.execute_query = Mock(side_effect=_execute_query) + + with caplog.at_level(logging.WARNING): + create_decision_constraints(graph_store) + + assert "Failed to drop legacy policy_id_unique constraint" in caplog.text