Skip to content

demo(dist2): VG004-VG006 across SQL/Go/Python#3

Open
eitamring wants to merge 2 commits intomainfrom
demo/dist-2-vg004-006
Open

demo(dist2): VG004-VG006 across SQL/Go/Python#3
eitamring wants to merge 2 commits intomainfrom
demo/dist-2-vg004-006

Conversation

@eitamring
Copy link
Copy Markdown
Contributor

@eitamring eitamring commented Mar 5, 2026

Purpose

This PR demonstrates selectivity/locking rules across SQL, Go database/sql, Goqu, Python ORM, and Python non-ORM paths.

Expected Findings In This PR

  • VG004 (unbounded-select): expected because demo includes boundedness violations (selects without limit).
  • VG005 (like-leading-wildcard): expected because demo includes LIKE '%...' patterns.
  • VG006 (select-for-update-no-where): expected because demo includes FOR UPDATE without WHERE.

These findings are intentionally introduced to document behavior and reviewer UX.

Why We Previously Failed In CI

The failure was workflow-level (Convert to reviewdog format) due to JSON-shape assumptions in jq, not rule misfires.

This branch includes the jq shape-normalization fix and pins VALK_GUARD_INSTALL_REF to the known-good build used in successful conversion.

How ORM AST Crawl Works In This PR

Valk Guard parses Python AST query forms and emits SQL/synthetic SQL that then flows through the same parser + rule pipeline as SQL files and Go queries.

That unified pipeline is why VG004-VG006 show consistently across ORM and non-ORM examples.

What We Gain

  • Cross-engine confidence for pagination/selectivity/locking checks.
  • Reproducible fixtures for tuning false positives in query-heavy services.
  • Better PR review signal because examples map directly to common production anti-patterns.

import goqulib "github.com/doug-martin/goqu/v9"

func GoquViolations() {
_ = goqulib.L("SELECT id, email FROM users WHERE active = true")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true


func GoquViolations() {
_ = goqulib.L("SELECT id, email FROM users WHERE active = true")
_ = goqulib.L("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1

func GoquViolations() {
_ = goqulib.L("SELECT id, email FROM users WHERE active = true")
_ = goqulib.L("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")
_ = goqulib.L("SELECT id FROM users FOR UPDATE")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

func GoquViolations() {
_ = goqulib.L("SELECT id, email FROM users WHERE active = true")
_ = goqulib.L("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1")
_ = goqulib.L("SELECT id FROM users FOR UPDATE")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE


func StdViolations(db *sql.DB) {
ctx := context.Background()
_, _ = db.QueryContext(ctx, "SELECT id, email FROM users WHERE active = true")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true



def raw_select_for_update_no_where(session: Session):
return session.execute(text("SELECT id FROM users FOR UPDATE")).all()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

@@ -0,0 +1 @@
SELECT id, email FROM users WHERE active = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id, email FROM users WHERE active = true

@@ -0,0 +1 @@
SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG005: LIKE/ILIKE with leading wildcard may prevent index usage; use a suffix pattern or full-text search | Query: SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1

@@ -0,0 +1 @@
SELECT id FROM users FOR UPDATE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [valk-guard] reported by reviewdog 🐶
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query: SELECT id FROM users FOR UPDATE

@@ -0,0 +1 @@
SELECT id FROM users FOR UPDATE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [valk-guard] reported by reviewdog 🐶
VG006: SELECT FOR UPDATE without WHERE may lock too many rows; add a WHERE clause | Query: SELECT id FROM users FOR UPDATE

@eitamring eitamring force-pushed the demo/dist-2-vg004-006 branch from a668be7 to d75b348 Compare March 6, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant