bricksentry 0.1.31__tar.gz → 0.1.32__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 (100) hide show
  1. {bricksentry-0.1.31 → bricksentry-0.1.32}/CHANGELOG.md +8 -0
  2. {bricksentry-0.1.31 → bricksentry-0.1.32}/PKG-INFO +4 -3
  3. {bricksentry-0.1.31 → bricksentry-0.1.32}/README.md +3 -2
  4. bricksentry-0.1.32/deploy/databricks-app/requirements.txt +1 -0
  5. {bricksentry-0.1.31 → bricksentry-0.1.32}/pyproject.toml +1 -1
  6. {bricksentry-0.1.31 → bricksentry-0.1.32}/server.json +2 -2
  7. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/__init__.py +1 -1
  8. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/assess.py +7 -0
  9. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/cli.py +3 -1
  10. bricksentry-0.1.32/src/bricksentry/governed.py +57 -0
  11. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/history.py +8 -0
  12. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/preview.py +23 -11
  13. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/databricks_template_schema.json +2 -2
  14. bricksentry-0.1.32/tests/test_0132.py +118 -0
  15. bricksentry-0.1.31/deploy/databricks-app/requirements.txt +0 -1
  16. {bricksentry-0.1.31 → bricksentry-0.1.32}/.gitignore +0 -0
  17. {bricksentry-0.1.31 → bricksentry-0.1.32}/CONTRIBUTING.md +0 -0
  18. {bricksentry-0.1.31 → bricksentry-0.1.32}/LICENSE +0 -0
  19. {bricksentry-0.1.31 → bricksentry-0.1.32}/SECURITY.md +0 -0
  20. {bricksentry-0.1.31 → bricksentry-0.1.32}/action.yml +0 -0
  21. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/container/Dockerfile +0 -0
  22. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/databricks-app/README.md +0 -0
  23. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/databricks-app/app.yaml +0 -0
  24. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/databricks-app/bricksentry.yml +0 -0
  25. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/databricks-app/databricks.yml +0 -0
  26. {bricksentry-0.1.31 → bricksentry-0.1.32}/deploy/databricks-app/grants.sql +0 -0
  27. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry.yml +0 -0
  28. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
  29. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_check_my_table.py +0 -0
  30. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
  31. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
  32. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  33. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_quickstart.py +0 -0
  34. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_validation.ipynb +0 -0
  35. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/bricksentry_validation.py +0 -0
  36. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/github-workflow.yml +0 -0
  37. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/databricks/policy.yml +0 -0
  38. {bricksentry-0.1.31 → bricksentry-0.1.32}/examples/demo/agent_loop_demo.py +0 -0
  39. {bricksentry-0.1.31 → bricksentry-0.1.32}/scripts/build_notebook.py +0 -0
  40. {bricksentry-0.1.31 → bricksentry-0.1.32}/scripts/render_demo_image.py +0 -0
  41. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/__main__.py +0 -0
  42. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/agent_tools.py +0 -0
  43. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/agent_view.py +0 -0
  44. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/backends/__init__.py +0 -0
  45. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/backends/base.py +0 -0
  46. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/backends/databricks_backend.py +0 -0
  47. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/backends/duckdb_backend.py +0 -0
  48. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/changes.py +0 -0
  49. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/cleanup.py +0 -0
  50. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/config.py +0 -0
  51. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/demo.py +0 -0
  52. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/diff.py +0 -0
  53. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/explain.py +0 -0
  54. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/github.py +0 -0
  55. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/job.py +0 -0
  56. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/job_demo.py +0 -0
  57. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/lineage.py +0 -0
  58. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/mcp_server.py +0 -0
  59. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/measures.py +0 -0
  60. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/models.py +0 -0
  61. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/netguard.py +0 -0
  62. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/notify.py +0 -0
  63. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/policy.py +0 -0
  64. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/policy_templates.py +0 -0
  65. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/py.typed +0 -0
  66. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/report.py +0 -0
  67. {bricksentry-0.1.31 → bricksentry-0.1.32}/src/bricksentry/validation.py +0 -0
  68. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/README.md +0 -0
  69. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
  70. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
  71. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
  72. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
  73. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
  74. {bricksentry-0.1.31 → bricksentry-0.1.32}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
  75. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/conftest.py +0 -0
  76. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0110.py +0 -0
  77. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0112.py +0 -0
  78. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0114.py +0 -0
  79. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0120.py +0 -0
  80. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0121.py +0 -0
  81. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0122.py +0 -0
  82. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0123.py +0 -0
  83. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0126.py +0 -0
  84. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0127.py +0 -0
  85. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0128.py +0 -0
  86. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0129.py +0 -0
  87. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0130.py +0 -0
  88. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_0131.py +0 -0
  89. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_018.py +0 -0
  90. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_019.py +0 -0
  91. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_assess_policy.py +0 -0
  92. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_check_notebook.py +0 -0
  93. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_databricks_and_uc.py +0 -0
  94. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_demo.py +0 -0
  95. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_diff.py +0 -0
  96. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_hr_notebook.py +0 -0
  97. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_notebook.py +0 -0
  98. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_notify_templates.py +0 -0
  99. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_preview_agents.py +0 -0
  100. {bricksentry-0.1.31 → bricksentry-0.1.32}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.32 (2026-11-22)
4
+
5
+ Fixes from a scale, adversarial and platform-feature round on 0.1.31 on a Free Edition workspace. It found no safety problem: previews took 20–33 s on 1 million rows and 27–29 s on 10 million with exact counts; 8 operations at once on the same tables finished cleanly with unique clones; partitioned, liquid-clustered, identity-column and CHECK-constraint tables previewed correctly; hostile column names, forbidden words in values and 300-clause SQL were handled.
6
+
7
+ - **Columns named like keywords can be previewed.** A write touching a column named `` `drop` `` (or `alter`, `grant`…) was refused as a DROP. Quoted names are now names to the keyword check; the check that the SQL doesn't name the production table still reads inside them. An unclosed `` ` `` or `"` is refused, and `"..."` is read both with and without backslash escapes, as engines differ.
8
+ - **Tables with column masks or row filters get one clear message.** Databricks refuses shallow clones and time travel on them (`COLUMN_MASKS_FEATURE_NOT_SUPPORTED`, `ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED`), so neither `preview_write` nor `check-last-change` can work on them. bricksentry now checks for masks and filters first and says so, with what to do instead, before creating anything; it also recognises the engine's error if the check can't read them. It doesn't copy governed data into the sandbox to work around this, because the sandbox may be readable by more people than the table.
9
+ - README: measured timings on 1 and 10 million rows; sampling on serverless mainly lowers cost, not time; the masked-table limit.
10
+
3
11
  ## 0.1.31 (2026-11-22)
4
12
 
5
13
  Fixes from two edge-case rounds on 0.1.30 on a Free Edition workspace: production was never changed in any scenario (writes to other tables, hidden statements, views, materialized views, column mapping and deletion vectors, `check-last-change` after OPTIMIZE, VACUUM, ALTER, RESTORE and overwrites, a write landing mid-check, Ctrl-C mid-run), and every rollback suggestion was confirmed by time travel.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.31
3
+ Version: 0.1.32
4
4
  Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for 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
@@ -203,7 +203,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
203
203
  Designed for agents:
204
204
 
205
205
  - **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
206
- - **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine. Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
206
+ - **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine, and so are columns named like keywords when quoted (`` `drop` ``). Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
207
207
  - **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
208
208
  - **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
209
209
  - **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
@@ -495,7 +495,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
495
495
 
496
496
  ## What a check costs
497
497
 
498
- The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Lineage lookups are one query per depth level, bounded by `lookback_days`.
498
+ The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. Measured on a Free Edition serverless warehouse with 0.1.31: a preview took 20–33 s on 1 million rows and 27–29 s on 10 million, `check-last-change` 27 s on 10 million. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. On serverless, sampling mainly lowers warehouse cost; the time is spent reading the tables either way. Lineage lookups are one query per depth level, bounded by `lookback_days`.
499
499
 
500
500
  ## Audit trail
501
501
 
@@ -531,6 +531,7 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
531
531
  ## Known limits (v0.1.x)
532
532
 
533
533
  - **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
534
+ - **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
534
535
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
535
536
  - **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
536
537
  - **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.28 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, the job task blocking a bad MERGE inside a real Databricks job, and worst-case rounds (50,000 NULL keys, near-max decimals, exotic types, 200-column tables) whose five findings were fixed in 0.1.26, a round of leak, data-shape and race tests whose four findings were fixed in 0.1.27, and a round on MERGE, allowlist bypasses, metadata injection, remote access and governance features whose findings were fixed in 0.1.28. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
@@ -155,7 +155,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
155
155
  Designed for agents:
156
156
 
157
157
  - **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
158
- - **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine. Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
158
+ - **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine, and so are columns named like keywords when quoted (`` `drop` ``). Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
159
159
  - **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
160
160
  - **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
161
161
  - **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
@@ -447,7 +447,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
447
447
 
448
448
  ## What a check costs
449
449
 
450
- The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Lineage lookups are one query per depth level, bounded by `lookback_days`.
450
+ The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. Measured on a Free Edition serverless warehouse with 0.1.31: a preview took 20–33 s on 1 million rows and 27–29 s on 10 million, `check-last-change` 27 s on 10 million. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. On serverless, sampling mainly lowers warehouse cost; the time is spent reading the tables either way. Lineage lookups are one query per depth level, bounded by `lookback_days`.
451
451
 
452
452
  ## Audit trail
453
453
 
@@ -483,6 +483,7 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
483
483
  ## Known limits (v0.1.x)
484
484
 
485
485
  - **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
486
+ - **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
486
487
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
487
488
  - **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
488
489
  - **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.28 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, the job task blocking a bad MERGE inside a real Databricks job, and worst-case rounds (50,000 NULL keys, near-max decimals, exotic types, 200-column tables) whose five findings were fixed in 0.1.26, a round of leak, data-shape and race tests whose four findings were fixed in 0.1.27, and a round on MERGE, allowlist bypasses, metadata injection, remote access and governance features whose findings were fixed in 0.1.28. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
@@ -0,0 +1 @@
1
+ bricksentry[databricks,mcp]==0.1.32
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bricksentry"
7
- version = "0.1.31"
7
+ version = "0.1.32"
8
8
  description = "Change impact analysis and deployment guardrails for data changes on Databricks, for 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"
@@ -8,12 +8,12 @@
8
8
  "source": "github"
9
9
  },
10
10
  "websiteUrl": "https://bricksentry.org",
11
- "version": "0.1.31",
11
+ "version": "0.1.32",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "pypi",
15
15
  "identifier": "bricksentry-mcp",
16
- "version": "0.1.31",
16
+ "version": "0.1.32",
17
17
  "runtimeHint": "uvx",
18
18
  "transport": {
19
19
  "type": "stdio"
@@ -23,4 +23,4 @@ __all__ = [
23
23
  "TableDiff",
24
24
  "Verdict",
25
25
  ]
26
- __version__ = "0.1.31"
26
+ __version__ = "0.1.32"
@@ -9,6 +9,7 @@ import uuid
9
9
  from datetime import datetime, timezone
10
10
  from typing import Any
11
11
 
12
+ from bricksentry import governed
12
13
  from bricksentry.backends.base import Backend, make_backend
13
14
  from bricksentry.config import Config
14
15
  from bricksentry.diff import diff_tables
@@ -210,11 +211,17 @@ class Sentry:
210
211
  raise ValueError(f"No keys configured for {target}; pass keys=[...] to preview_write")
211
212
  clone = sandbox_name(self.config.sandbox_schema, target)
212
213
  rewritten = rewrite_for_preview(sql, target, clone, self.backend.quote)
214
+ what = governed.describe(self.backend, target)
215
+ if what:
216
+ raise ValueError(governed.preview_message(target, what))
213
217
  schema = ".".join(clone.split(".")[:-1])
214
218
  created = bool(schema and self.backend.ensure_schema(schema))
215
219
  try:
216
220
  self.backend.clone(target, clone)
217
221
  except Exception as e:
222
+ what = governed.from_error(e)
223
+ if what:
224
+ raise ValueError(governed.preview_message(target, what)) from None
218
225
  raise RuntimeError(
219
226
  f"Could not clone {target} to preview the write: {_first_line(e)}. Check the table name "
220
227
  f"and that you can create tables in {schema or 'the sandbox schema'}."
@@ -246,7 +246,9 @@ def check_last_change(table, keys, version, since, sample_pct, allow_no_change,
246
246
  click.echo(str(e), err=True)
247
247
  sys.exit(0 if allow_no_change else 2)
248
248
  except (NotImplementedError, ValueError, RuntimeError) as e:
249
- raise click.ClickException(str(e)) from e
249
+ err = click.ClickException(str(e))
250
+ err.exit_code = 2 # never 1, which means BLOCK
251
+ raise err from e
250
252
  md = to_markdown(a)
251
253
  if output:
252
254
  Path(output).write_text(md)
@@ -0,0 +1,57 @@
1
+ """Tables with Unity Catalog column masks or row filters.
2
+
3
+ Databricks refuses both shallow clones and time travel (``VERSION AS OF``) on these tables
4
+ (``COLUMN_MASKS_FEATURE_NOT_SUPPORTED`` / ``ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED``).
5
+ So bricksentry can't preview a write on them (no clone) or compare two versions of them
6
+ (no time travel), and it says so up front, in one clear message, instead of failing in the
7
+ middle. It never copies governed data into the scratch schema as a workaround: the scratch
8
+ schema may be readable by more people than the table, which is what masks and filters
9
+ exist to prevent. And it never suggests removing the mask or filter.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Any
15
+
16
+ _CODES = ("COLUMN_MASKS_FEATURE_NOT_SUPPORTED", "ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED")
17
+
18
+
19
+ def describe(db: Any, table: str) -> str | None:
20
+ """"a column mask (on amount)", "a row filter", both, or None. None also when the
21
+ protections can't be read; the engine's own error is then recognised by ``from_error``."""
22
+ try:
23
+ p = (db.protections([table]) or {}).get(table) or {}
24
+ except Exception:
25
+ return None
26
+ parts = []
27
+ if p.get("masked"):
28
+ cols = ", ".join(sorted(p["masked"]))
29
+ parts.append(f"a column mask (on {cols})")
30
+ if p.get("row_filter"):
31
+ parts.append("a row filter")
32
+ return " and ".join(parts) or None
33
+
34
+
35
+ def from_error(e: BaseException) -> str | None:
36
+ text = str(e)
37
+ if _CODES[0] in text and _CODES[1] in text:
38
+ return "a column mask and a row filter"
39
+ if _CODES[0] in text:
40
+ return "a column mask"
41
+ if _CODES[1] in text:
42
+ return "a row filter"
43
+ return None
44
+
45
+
46
+ def check_message(table: str, what: str) -> str:
47
+ return (f"{table} has {what}. Databricks doesn't allow reading earlier versions of tables with column "
48
+ "masks or row filters (time travel and clones are refused), so check-last-change can't compare "
49
+ "versions of it. Check changes before they reach it instead: preview or assess the write on the "
50
+ "table that feeds it, or on a dev copy without the mask or filter.")
51
+
52
+
53
+ def preview_message(table: str, what: str) -> str:
54
+ return (f"{table} has {what}. Databricks doesn't allow shallow clones of tables with column masks or row "
55
+ "filters, and bricksentry won't copy governed data into the sandbox, so this write can't be "
56
+ "previewed here. Preview it on a dev copy of the table without the mask or filter, or on the table "
57
+ "that feeds it.")
@@ -14,6 +14,8 @@ from dataclasses import dataclass, field
14
14
  from datetime import datetime, timezone
15
15
  from typing import TYPE_CHECKING, Any
16
16
 
17
+ from bricksentry import governed
18
+
17
19
  if TYPE_CHECKING: # pragma: no cover
18
20
  from bricksentry.assess import Sentry
19
21
  from bricksentry.models import Assessment
@@ -253,6 +255,9 @@ def check_change(
253
255
  if not _NAME.fullmatch(table):
254
256
  raise ValueError(f"table must be schema.table or catalog.schema.table; got {table!r}")
255
257
 
258
+ what = governed.describe(db, table)
259
+ if what:
260
+ raise ValueError(governed.check_message(table, what))
256
261
  history = _read_history(db, table, history_limit)
257
262
  change = pick_change(table, history, version=version, since=since)
258
263
  keys = keys or sentry.config.spec(table).keys or db.primary_key(table)
@@ -273,6 +278,9 @@ def check_change(
273
278
  try:
274
279
  db.clone_version(table, target, v)
275
280
  except Exception as e:
281
+ what = governed.from_error(e)
282
+ if what:
283
+ raise ValueError(governed.check_message(table, what)) from None
276
284
  raise RuntimeError(
277
285
  f"Could not read version {v} of {table}: its files may have been removed by VACUUM, "
278
286
  f"or you may lack CREATE TABLE on {scratch}. ({str(e).strip()[:300]})") from None
@@ -63,7 +63,7 @@ def _strip_quotes(name: str) -> str:
63
63
  return name.replace("`", "").replace('"', "").lower()
64
64
 
65
65
 
66
- def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
66
+ def _scan(sql: str, backslash: bool = True, idents: bool = False) -> list[tuple[str, int, int]]:
67
67
  """Split ``sql`` into ("code" | "string" | "comment", start, end) pieces.
68
68
 
69
69
  '...' is a string literal. `...` and "..." are skipped over as single tokens (so a
@@ -88,7 +88,7 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
88
88
  def skip_quoted(j: int, q: str) -> int:
89
89
  j += 1
90
90
  while j < n:
91
- if sql[j] == "\\" and q != "`" and (backslash or q != "'"):
91
+ if sql[j] == "\\" and q != "`" and backslash:
92
92
  j += 2
93
93
  continue
94
94
  if sql[j] == q:
@@ -102,7 +102,14 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
102
102
  while i < n:
103
103
  c = sql[i]
104
104
  if c in "`\"":
105
- i = skip_quoted(i, c)
105
+ j = skip_quoted(i, c)
106
+ if idents: # report quoted names as their own pieces (for the keyword check)
107
+ if j >= n and not (j - i >= 2 and sql[j - 1] == c):
108
+ raise PreviewGuardError(f"The SQL has a quote ({c}) that is never closed.")
109
+ close("code", start, i)
110
+ close("ident", i, j)
111
+ start = j
112
+ i = j
106
113
  elif c == "'":
107
114
  close("code", start, i)
108
115
  j = skip_quoted(i, "'")
@@ -128,15 +135,20 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
128
135
  return pieces
129
136
 
130
137
 
131
- def _strip_sql_comments_and_strings(sql: str, backslash: bool = True) -> str:
132
- """The SQL with comments blanked and '...' literals emptied, for the guards to inspect."""
133
- return "".join(sql[a:b] if k == "code" else (" " if k == "comment" else "''")
134
- for k, a, b in _scan(sql, backslash))
138
+ _BLANK = {"comment": " ", "string": "''", "ident": "`_`"}
135
139
 
136
140
 
137
- def _masked(sql: str) -> list[str]:
138
- """The SQL as each engine family would read it; every guard must pass on all of them."""
139
- return [_strip_sql_comments_and_strings(sql, True), _strip_sql_comments_and_strings(sql, False)]
141
+ def _strip_sql_comments_and_strings(sql: str, backslash: bool = True, idents: bool = False) -> str:
142
+ """The SQL with comments blanked and '...' literals emptied, for the guards to inspect.
143
+ With ``idents``, quoted names (`drop`, "drop") are blanked too."""
144
+ return "".join(sql[a:b] if k == "code" else _BLANK[k] for k, a, b in _scan(sql, backslash, idents))
145
+
146
+
147
+ def _masked(sql: str, idents: bool = False) -> list[str]:
148
+ """The SQL as each engine family would read it; every guard must pass on all of them.
149
+ ``idents`` blanks quoted names: right for keyword and ``;`` checks (a column named
150
+ `drop` is a name, not a statement), wrong for finding the production table's name."""
151
+ return [_strip_sql_comments_and_strings(sql, True, idents), _strip_sql_comments_and_strings(sql, False, idents)]
140
152
 
141
153
 
142
154
  _LEADING_COMMENTS = re.compile(r"\A(?:\s+|--[^\n]*(?:\n|\Z)|/\*.*?\*/)*", re.S)
@@ -166,7 +178,7 @@ def statement_head(sql: str) -> str:
166
178
  def rewrite_for_preview(sql: str, target: str, clone: str, quote) -> str:
167
179
  """Return SQL that writes to ``clone`` instead of ``target``. Raises PreviewGuardError if unsafe."""
168
180
  body = sql.strip().rstrip(";").strip()
169
- for code in _masked(body):
181
+ for code in _masked(body, idents=True):
170
182
  if ";" in code:
171
183
  raise PreviewGuardError(
172
184
  "preview_write accepts exactly one SQL statement. Preview each write separately, in the order they "
@@ -86,10 +86,10 @@
86
86
  },
87
87
  "bricksentry_version": {
88
88
  "type": "string",
89
- "default": "0.1.31",
89
+ "default": "0.1.32",
90
90
  "description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
91
91
  "pattern": "^\\d+\\.\\d+\\.\\d+$",
92
- "pattern_match_failure_message": "Use a version like 0.1.31.",
92
+ "pattern_match_failure_message": "Use a version like 0.1.32.",
93
93
  "order": 10
94
94
  }
95
95
  },
@@ -0,0 +1,118 @@
1
+ """0.1.32: findings from the scale, adversarial and platform-feature round on 0.1.31."""
2
+
3
+ import pytest
4
+ from click.testing import CliRunner
5
+ from test_0114 import FakeDelta
6
+
7
+ from bricksentry import governed, job
8
+ from bricksentry.assess import Sentry
9
+ from bricksentry.cli import main
10
+ from bricksentry.config import Config
11
+ from bricksentry.preview import PreviewGuardError, rewrite_for_preview
12
+
13
+
14
+ def q(p):
15
+ return f"`{p}`"
16
+
17
+
18
+ def rw(sql, target="main.s.t"):
19
+ return rewrite_for_preview(sql, target, "sb.x.t__preview_0123abcd", q)
20
+
21
+
22
+ # --- a column named like a keyword -------------------------------------------------
23
+ def test_quoted_keyword_names_are_names():
24
+ assert rw("UPDATE main.s.t SET `drop` = 1 WHERE id = 2").startswith("UPDATE `sb`")
25
+ assert rw("INSERT INTO main.s.t (`drop`, `alter`, `grant`) VALUES (1, 2, 3)")
26
+ assert rw('UPDATE main.s.t SET "truncate" = 1')
27
+ assert rw("UPDATE main.s.t SET `a;b` = 1")
28
+ assert rw("UPDATE `main`.`s`.`t` SET `drop` = 1")
29
+
30
+
31
+ @pytest.mark.parametrize("sql", [
32
+ "UPDATE main.s.t SET drop = 1", # unquoted: still a keyword
33
+ "UPDATE main.s.t SET `drop` = 1; DROP TABLE main.s.prod",
34
+ 'UPDATE main.s.t SET a = "x\\"; DROP TABLE main.s.prod; --"', # DuckDB: no escapes in "..."
35
+ 'UPDATE main.s.t SET a = 1 "; DROP TABLE main.s.prod', # never closed
36
+ "UPDATE main.s.t SET a = 1 `; DROP TABLE main.s.prod",
37
+ ])
38
+ def test_quoted_names_hide_nothing(sql):
39
+ with pytest.raises(PreviewGuardError):
40
+ rw(sql)
41
+
42
+
43
+ def test_production_name_in_backticks_is_still_found():
44
+ # The leftover check still reads inside backticks: a second reference to production refused.
45
+ with pytest.raises(PreviewGuardError):
46
+ rewrite_for_preview("INSERT INTO {{target}} SELECT * FROM `main`.`s`.`t`", "main.s.t",
47
+ "sb.x.t__preview_0123abcd", q)
48
+
49
+
50
+ # --- tables with column masks or row filters -----------------------------------------
51
+ class Governed(FakeDelta):
52
+ def __init__(self, prot=None, clone_error=None):
53
+ super().__init__()
54
+ self.prot = prot or {}
55
+ self.clone_error = clone_error
56
+
57
+ def protections(self, tables):
58
+ return {t: self.prot[t] for t in tables if t in self.prot}
59
+
60
+ def clone_version(self, source, target, version):
61
+ if self.clone_error:
62
+ raise RuntimeError(self.clone_error)
63
+ return super().clone_version(source, target, version)
64
+
65
+ def clone(self, source, target):
66
+ if self.clone_error:
67
+ raise RuntimeError(self.clone_error)
68
+ return super().clone(source, target)
69
+
70
+
71
+ def sentry(db):
72
+ return Sentry(Config.from_dict({"assessment_store": False, "sandbox_schema": "scratch",
73
+ "tables": {"sales.orders": {"keys": ["order_id"]}}}), backend=db)
74
+
75
+
76
+ def test_describe():
77
+ db = Governed({"sales.orders": {"masked": ["ssn", "amount"], "row_filter": True}})
78
+ assert governed.describe(db, "sales.orders") == "a column mask (on amount, ssn) and a row filter"
79
+ assert governed.describe(db, "sales.other") is None
80
+ assert governed.from_error(RuntimeError("[COLUMN_MASKS_FEATURE_NOT_SUPPORTED.TIME_TRAVEL] x")) == "a column mask"
81
+ assert governed.from_error(RuntimeError("[ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED.CLONE]")) == "a row filter"
82
+ assert governed.from_error(RuntimeError("other")) is None
83
+
84
+
85
+ def test_check_change_refuses_up_front():
86
+ db = Governed({"sales.orders": {"masked": ["amount"], "row_filter": False}})
87
+ with pytest.raises(ValueError, match="sales.orders has a column mask \\(on amount\\).*can't compare versions"):
88
+ sentry(db).check_change("sales.orders")
89
+ assert not [t for t in FakeDelta.list_tables(db, "scratch")] # nothing was cloned
90
+
91
+
92
+ def test_check_change_recognises_the_engine_error():
93
+ db = Governed(clone_error="[ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED.TIME_TRAVEL] Time travel is not supported")
94
+ with pytest.raises(ValueError, match="has a row filter.*dev copy without the mask or filter"):
95
+ sentry(db).check_change("sales.orders")
96
+
97
+
98
+ def test_preview_refuses_up_front_and_never_suggests_unmasking():
99
+ db = Governed({"sales.orders": {"masked": [], "row_filter": True}})
100
+ with pytest.raises(ValueError) as e:
101
+ sentry(db).preview_write("UPDATE {{target}} SET amount = 0 WHERE order_id = 1", "sales.orders")
102
+ msg = str(e.value)
103
+ assert "won't copy governed data" in msg and "drop" not in msg.lower() and "remove" not in msg.lower()
104
+ db = Governed(clone_error="[COLUMN_MASKS_FEATURE_NOT_SUPPORTED.CLONE] Shallow clone not supported")
105
+ with pytest.raises(ValueError, match="has a column mask"):
106
+ sentry(db).preview_write("UPDATE {{target}} SET amount = 0 WHERE order_id = 1", "sales.orders")
107
+
108
+
109
+ def test_cli_and_job_report_it_cleanly(monkeypatch, tmp_path):
110
+ db = Governed({"sales.orders": {"masked": ["amount"], "row_filter": False}})
111
+ monkeypatch.setattr("bricksentry.assess.make_backend", lambda spec: db)
112
+ cfg = tmp_path / "bricksentry.yml"
113
+ cfg.write_text("sandbox_schema: scratch\nassessment_store: false\nlineage: {type: static}\n")
114
+ r = CliRunner().invoke(main, ["check-last-change", "sales.orders", "-c", str(cfg), "--no-notify"])
115
+ assert r.exit_code == 2 and "has a column mask" in r.output and "Traceback" not in r.output
116
+ lines: list[str] = []
117
+ code = job.run(["--tables", "sales.orders", "--scratch-schema", "scratch"], backend=db, out=lines.append)
118
+ assert code == 2 and "has a column mask" in "\n".join(lines)
@@ -1 +0,0 @@
1
- bricksentry[databricks,mcp]==0.1.31
File without changes
File without changes
File without changes
File without changes