bricksentry 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {bricksentry-0.1.1 → bricksentry-0.1.2}/CHANGELOG.md +6 -1
  2. {bricksentry-0.1.1 → bricksentry-0.1.2}/PKG-INFO +3 -3
  3. {bricksentry-0.1.1 → bricksentry-0.1.2}/README.md +2 -2
  4. {bricksentry-0.1.1 → bricksentry-0.1.2}/examples/databricks/policy.yml +1 -0
  5. {bricksentry-0.1.1 → bricksentry-0.1.2}/pyproject.toml +1 -1
  6. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/__init__.py +1 -1
  7. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/cli.py +1 -0
  8. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/diff.py +16 -8
  9. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/explain.py +2 -0
  10. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/models.py +2 -0
  11. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/policy.py +11 -1
  12. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/test_assess_policy.py +11 -0
  13. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/test_diff.py +23 -0
  14. {bricksentry-0.1.1 → bricksentry-0.1.2}/.gitignore +0 -0
  15. {bricksentry-0.1.1 → bricksentry-0.1.2}/CONTRIBUTING.md +0 -0
  16. {bricksentry-0.1.1 → bricksentry-0.1.2}/LICENSE +0 -0
  17. {bricksentry-0.1.1 → bricksentry-0.1.2}/SECURITY.md +0 -0
  18. {bricksentry-0.1.1 → bricksentry-0.1.2}/action.yml +0 -0
  19. {bricksentry-0.1.1 → bricksentry-0.1.2}/examples/databricks/bricksentry.yml +0 -0
  20. {bricksentry-0.1.1 → bricksentry-0.1.2}/examples/databricks/github-workflow.yml +0 -0
  21. {bricksentry-0.1.1 → bricksentry-0.1.2}/examples/demo/agent_loop_demo.py +0 -0
  22. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/agent_tools.py +0 -0
  23. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/assess.py +0 -0
  24. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/backends/__init__.py +0 -0
  25. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/backends/base.py +0 -0
  26. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/backends/databricks_backend.py +0 -0
  27. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/backends/duckdb_backend.py +0 -0
  28. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/changes.py +0 -0
  29. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/config.py +0 -0
  30. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/demo.py +0 -0
  31. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/github.py +0 -0
  32. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/lineage.py +0 -0
  33. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/mcp_server.py +0 -0
  34. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/preview.py +0 -0
  35. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/py.typed +0 -0
  36. {bricksentry-0.1.1 → bricksentry-0.1.2}/src/bricksentry/report.py +0 -0
  37. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/conftest.py +0 -0
  38. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/test_databricks_and_uc.py +0 -0
  39. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/test_demo.py +0 -0
  40. {bricksentry-0.1.1 → bricksentry-0.1.2}/tests/test_preview_agents.py +0 -0
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.1 (unreleased)
3
+ ## 0.1.2 (2026-11-10)
4
+
5
+ - Fix: rows whose key is NULL are now matched null-safely. Before, each such row was counted as both added and removed (found on a real Databricks table with a NULL `state`).
6
+ - New `null_keys` policy condition and default `null-keys` rule (warn) when a change introduces rows with a NULL key; summaries mention NULL keys.
7
+
8
+ ## 0.1.1 (2026-11-10)
4
9
 
5
10
  - New `bricksentry demo` command: the full agent safety loop on a local 20,000-row example in about 30 seconds (`pip install "bricksentry[duckdb]"`). `--report FILE` also writes the pull-request comment.
6
11
  - Fix: the "Review requested from" line in PR comments no longer runs into the line above it.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
5
5
  Project-URL: Homepage, https://bricksentry.org
6
6
  Project-URL: Documentation, https://bricksentry.org/docs
@@ -47,7 +47,7 @@ Description-Content-Type: text/markdown
47
47
 
48
48
  [![PyPI](https://img.shields.io/pypi/v/bricksentry)](https://pypi.org/project/bricksentry/) [![Python](https://img.shields.io/pypi/pyversions/bricksentry)](https://pypi.org/project/bricksentry/) [![CI](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
49
49
 
50
- **Change-safety for Databricks pipelines and the AI agents that edit them.**
50
+ ***Change-safety for Databricks pipelines and the AI agents that edit them.***
51
51
 
52
52
  **Website and docs: [bricksentry.org](https://bricksentry.org)**
53
53
 
@@ -190,7 +190,7 @@ policy: policy.yml
190
190
 
191
191
  ### Policy conditions
192
192
 
193
- `table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
193
+ `table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
194
194
 
195
195
  All conditions in a `when` must hold. The most severe matching rule sets the verdict. Unknown conditions are rejected at load time, so a typo can't silently disable a rule.
196
196
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![PyPI](https://img.shields.io/pypi/v/bricksentry)](https://pypi.org/project/bricksentry/) [![Python](https://img.shields.io/pypi/pyversions/bricksentry)](https://pypi.org/project/bricksentry/) [![CI](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
4
4
 
5
- **Change-safety for Databricks pipelines and the AI agents that edit them.**
5
+ ***Change-safety for Databricks pipelines and the AI agents that edit them.***
6
6
 
7
7
  **Website and docs: [bricksentry.org](https://bricksentry.org)**
8
8
 
@@ -145,7 +145,7 @@ policy: policy.yml
145
145
 
146
146
  ### Policy conditions
147
147
 
148
- `table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
148
+ `table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
149
149
 
150
150
  All conditions in a `when` must hold. The most severe matching rule sets the verdict. Unknown conditions are rejected at load time, so a typo can't silently disable a rule.
151
151
 
@@ -6,6 +6,7 @@ notify_owners_on: needs_human
6
6
  rules:
7
7
  - {name: diff-failed, when: {diff_error: true}, then: needs_human}
8
8
  - {name: duplicate-keys, when: {duplicate_keys: true}, then: block}
9
+ - {name: null-keys, when: {null_keys: true}, then: warn}
9
10
  - {name: dropped-column, when: {column_removed: true}, then: needs_human}
10
11
  - {name: type-change, when: {column_type_changed: true}, then: warn}
11
12
  - {name: certified-downstream, when: {downstream_tag: certified}, then: needs_human}
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bricksentry"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -23,4 +23,4 @@ __all__ = [
23
23
  "TableDiff",
24
24
  "Verdict",
25
25
  ]
26
- __version__ = "0.1.1"
26
+ __version__ = "0.1.2"
@@ -222,6 +222,7 @@ notify_owners_on: needs_human
222
222
  rules:
223
223
  - {name: diff-failed, when: {diff_error: true}, then: needs_human}
224
224
  - {name: duplicate-keys, when: {duplicate_keys: true}, then: block}
225
+ - {name: null-keys, when: {null_keys: true}, then: warn}
225
226
  - {name: dropped-column, when: {column_removed: true}, then: needs_human}
226
227
  - {name: type-change, when: {column_type_changed: true}, then: warn}
227
228
  - {name: certified-downstream, when: {downstream_tag: certified}, then: needs_human}
@@ -61,13 +61,18 @@ def diff_tables(
61
61
  if columns:
62
62
  common = [c for c in common if c in columns]
63
63
 
64
+ # A marker column says whether a joined row exists on each side. Testing the key
65
+ # for NULL instead would count a NULL-key row as both added and removed.
66
+ present = q("__bs_present")
67
+
64
68
  def side(tbl: str, alias: str) -> str:
65
69
  where = f" WHERE {backend.sample_predicate(keys, sample_pct)}" if sample_pct else ""
66
- return f"{alias} AS (SELECT * FROM {backend.qualified(tbl)}{where})"
70
+ return f"{alias} AS (SELECT *, 1 AS {present} FROM {backend.qualified(tbl)}{where})"
67
71
 
68
72
  ctes = f"WITH {side(base, 'b_src')}, {side(candidate, 'c_src')}"
69
- join_on = " AND ".join(f"b.{q(k)} = c.{q(k)}" for k in keys)
70
- k0 = q(keys[0])
73
+ # Null-safe key match: a NULL key in production matches a NULL key in the candidate.
74
+ join_on = " AND ".join(f"b.{q(k)} IS NOT DISTINCT FROM c.{q(k)}" for k in keys)
75
+ in_b, in_c = f"b.{present} IS NOT NULL", f"c.{present} IS NOT NULL"
71
76
 
72
77
  def cmp(col: str) -> str:
73
78
  bc, cc = f"b.{q(col)}", f"c.{q(col)}"
@@ -76,12 +81,12 @@ def diff_tables(
76
81
  bc, cc = f"CAST({bc} AS {st})", f"CAST({cc} AS {st})"
77
82
  return f"{bc} IS DISTINCT FROM {cc}"
78
83
 
79
- both = f"b.{k0} IS NOT NULL AND c.{k0} IS NOT NULL"
84
+ both = f"{in_b} AND {in_c}"
80
85
  any_diff = " OR ".join(f"({cmp(c)})" for c in common) or "FALSE"
81
86
 
82
87
  selects = [
83
- f"SUM(CASE WHEN b.{k0} IS NULL THEN 1 ELSE 0 END) AS added_rows",
84
- f"SUM(CASE WHEN c.{k0} IS NULL THEN 1 ELSE 0 END) AS removed_rows",
88
+ f"SUM(CASE WHEN NOT ({in_b}) THEN 1 ELSE 0 END) AS added_rows",
89
+ f"SUM(CASE WHEN NOT ({in_c}) THEN 1 ELSE 0 END) AS removed_rows",
85
90
  f"SUM(CASE WHEN {both} AND ({any_diff}) THEN 1 ELSE 0 END) AS changed_rows",
86
91
  f"SUM(CASE WHEN {both} AND NOT ({any_diff}) THEN 1 ELSE 0 END) AS unchanged_rows",
87
92
  ]
@@ -96,7 +101,8 @@ def diff_tables(
96
101
 
97
102
  # Row counts, nulls, numeric sums per side.
98
103
  def profile(tbl_cte: str, cols: dict[str, str]) -> dict:
99
- parts = ["COUNT(*) AS n_rows"]
104
+ any_null_key = " OR ".join(f"{q(k)} IS NULL" for k in keys)
105
+ parts = ["COUNT(*) AS n_rows", f"SUM(CASE WHEN {any_null_key} THEN 1 ELSE 0 END) AS null_keys"]
100
106
  for i, col in enumerate(common):
101
107
  parts.append(f"SUM(CASE WHEN {q(col)} IS NULL THEN 1 ELSE 0 END) AS nul_{i}")
102
108
  if backend.is_numeric(cols[col]):
@@ -147,7 +153,7 @@ def diff_tables(
147
153
  continue
148
154
  b_seg = f"b.{q(seg)}" if seg in b_cols else "NULL"
149
155
  c_seg = f"c.{q(seg)}" if seg in c_cols else "NULL"
150
- affected = f"(b.{k0} IS NULL OR c.{k0} IS NULL OR ({any_diff}))"
156
+ affected = f"(NOT ({in_b}) OR NOT ({in_c}) OR ({any_diff}))"
151
157
  sql = (
152
158
  f"{ctes} SELECT COALESCE({c_seg}, {b_seg}) AS seg_value, COUNT(*) AS n "
153
159
  f"FROM b_src b FULL OUTER JOIN c_src c ON {join_on} WHERE {affected} "
@@ -171,6 +177,8 @@ def diff_tables(
171
177
  columns=col_changes,
172
178
  duplicate_keys_base=dupes("b_src"),
173
179
  duplicate_keys_candidate=dupes("c_src"),
180
+ null_keys_base=int(pb.get("null_keys") or 0),
181
+ null_keys_candidate=int(pc.get("null_keys") or 0),
174
182
  segments=segments,
175
183
  sampled_pct=sample_pct,
176
184
  )
@@ -73,6 +73,8 @@ def explain_diff(d: TableDiff) -> str:
73
73
 
74
74
  if d.duplicate_keys_candidate > d.duplicate_keys_base:
75
75
  s += f". WARNING: {_n(d.duplicate_keys_candidate)} duplicate key(s) on {', '.join(d.keys)}"
76
+ if d.null_keys_candidate:
77
+ s += f". Note: {_n(d.null_keys_candidate)} row(s) have a NULL key ({', '.join(d.keys)})"
76
78
  if d.sampled_pct:
77
79
  s += f" (based on a {d.sampled_pct:g}% key sample)"
78
80
  return s + "."
@@ -85,6 +85,8 @@ class TableDiff:
85
85
  columns: list[ColumnChange] = field(default_factory=list)
86
86
  duplicate_keys_base: int = 0
87
87
  duplicate_keys_candidate: int = 0
88
+ null_keys_base: int = 0
89
+ null_keys_candidate: int = 0
88
90
  segments: list[Segment] = field(default_factory=list)
89
91
  sampled_pct: float | None = None
90
92
  error: str | None = None
@@ -9,6 +9,9 @@ never from an LLM, so agents and CI get the same answer for the same change.
9
9
  - name: duplicate-keys
10
10
  when: {duplicate_keys: true}
11
11
  then: block
12
+ - name: new-null-keys
13
+ when: {null_keys: true}
14
+ then: warn
12
15
  - name: dropped-column
13
16
  when: {column_removed: true}
14
17
  then: needs_human
@@ -41,6 +44,7 @@ DEFAULT_POLICY: dict[str, Any] = {
41
44
  "rules": [
42
45
  {"name": "diff-failed", "when": {"diff_error": True}, "then": "needs_human"},
43
46
  {"name": "duplicate-keys", "when": {"duplicate_keys": True}, "then": "block"},
47
+ {"name": "null-keys", "when": {"null_keys": True}, "then": "warn"},
44
48
  {"name": "dropped-column", "when": {"column_removed": True}, "then": "needs_human"},
45
49
  {"name": "type-change", "when": {"column_type_changed": True}, "then": "warn"},
46
50
  {"name": "certified-downstream", "when": {"downstream_tag": "certified"}, "then": "needs_human"},
@@ -57,7 +61,7 @@ KNOWN_CONDITIONS = {
57
61
  "table", "tag", "downstream_tag", "downstream_kind", "downstream_count_gt",
58
62
  "removed_pct_gt", "added_pct_gt", "changed_pct_gt", "row_count_change_pct_gt",
59
63
  "row_count_drop_pct_gt", "column_removed", "column_type_changed", "column_added",
60
- "duplicate_keys", "column", "sum_change_pct_gt", "null_increase_gt",
64
+ "duplicate_keys", "null_keys", "column", "sum_change_pct_gt", "null_increase_gt",
61
65
  "any_change", "diff_error",
62
66
  }
63
67
 
@@ -164,6 +168,12 @@ def _match(
164
168
  return False, ""
165
169
  reasons.append(f"{diff.duplicate_keys_candidate} duplicate key(s) in candidate (base had {diff.duplicate_keys_base})")
166
170
  continue
171
+ if cond == "null_keys":
172
+ new_nulls = diff.null_keys_candidate > diff.null_keys_base
173
+ if new_nulls != bool(val):
174
+ return False, ""
175
+ reasons.append(f"{diff.null_keys_candidate} row(s) with a NULL key in candidate (base had {diff.null_keys_base})")
176
+ continue
167
177
  if cond == "column_removed":
168
178
  if bool(diff.schema.removed) != bool(val):
169
179
  return False, ""
@@ -74,3 +74,14 @@ def test_changed_tables_from_files():
74
74
  cfg = Config.from_dict({"tables": {"main.sales.orders": {"keys": ["id"], "paths": ["src/orders/**", "resources/orders.yml"]}}})
75
75
  assert tables_for_files(cfg, ["src/orders/transform.py"]) == ["main.sales.orders"]
76
76
  assert tables_for_files(cfg, ["README.md"]) == []
77
+
78
+
79
+ def test_new_null_keys_warn(backend):
80
+ from bricksentry import Sentry
81
+
82
+ backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
83
+ backend.execute("UPDATE sales_ci.orders SET order_id = NULL WHERE order_id = 7")
84
+ cfg = Config.from_dict({"tables": {"sales.orders": {"keys": ["order_id"]}}, "lineage": {"type": "static"}})
85
+ a = Sentry(cfg, backend=backend).assess(["sales.orders"])
86
+ assert "null-keys" in {h.rule for h in a.hits}
87
+ assert "NULL key" in a.tables[0].summary
@@ -73,3 +73,26 @@ def test_composite_keys(backend):
73
73
  backend.execute("UPDATE sales_ci.orders SET status = 'late' WHERE order_id = 7")
74
74
  d = diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id", "region"])
75
75
  assert d.changed_rows == 1
76
+
77
+
78
+ def test_null_keys_are_matched_not_double_counted(backend):
79
+ # Regression: a row whose key is NULL used to count as both added and removed.
80
+ backend.execute("CREATE SCHEMA s")
81
+ backend.execute(
82
+ "CREATE TABLE s.base AS SELECT * FROM (VALUES (NULL, 1.0), ('CA', 2.0), ('TX', 3.0), ('NY', 4.0)) t(state, v)"
83
+ )
84
+ # Unchanged NULL-key row: must be matched, not reported as added + removed.
85
+ backend.execute("CREATE TABLE s.same AS SELECT * FROM s.base")
86
+ d = diff_tables(backend, "s.base", "s.same", ["state"])
87
+ assert (d.added_rows, d.removed_rows, d.changed_rows) == (0, 0, 0)
88
+ assert d.is_identical and d.null_keys_base == 1
89
+
90
+ # NULL-key row changed: one changed row, nothing added or removed.
91
+ backend.execute("CREATE TABLE s.chg AS SELECT state, CASE WHEN state IS NULL THEN 9.0 ELSE v END AS v FROM s.base")
92
+ d = diff_tables(backend, "s.base", "s.chg", ["state"])
93
+ assert (d.added_rows, d.removed_rows, d.changed_rows) == (0, 0, 1)
94
+
95
+ # DELETE of three rows including the NULL-key row.
96
+ backend.execute("CREATE TABLE s.del AS SELECT * FROM s.base WHERE state = 'NY'")
97
+ d = diff_tables(backend, "s.base", "s.del", ["state"])
98
+ assert (d.added_rows, d.removed_rows) == (0, 3)
File without changes
File without changes
File without changes
File without changes
File without changes