Repository navigation
demo(dist4): VG106-VG111 with ORM/non-ORM coverage #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Dist 4: VG106-VG111 | ||
|
|
||
| This demo bundle intentionally triggers: | ||
|
|
||
| - VG106 (unknown filter column) | ||
| - VG107 (unknown table reference) | ||
| - VG108 (ambiguous unqualified column) | ||
| - VG109 (orphan migration table) | ||
| - VG110 (duplicate model column mapping) | ||
| - VG111 (Go inferred table/column mapping risk) | ||
|
|
||
| Coverage in this bundle: | ||
|
|
||
| - SQL schema + query files | ||
| - Python ORM models/queries | ||
| - Python non-ORM raw SQL queries | ||
| - Go models for VG110 and VG111 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package demo | ||
|
|
||
| // VG110User intentionally maps the same DB column twice. | ||
| type VG110User struct { | ||
| ID int64 `db:"id"` | ||
| LegacyID int64 `db:"id"` | ||
| Email string `db:"email"` | ||
| } | ||
|
|
||
| func (VG110User) TableName() string { return "vg110_users" } | ||
|
|
||
| // RiskyInferred intentionally relies on inferred table and column mapping. | ||
| type RiskyInferred struct { | ||
| ID int64 | ||
| Email string | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from sqlalchemy import Column, Integer, String, text | ||
| from sqlalchemy.orm import DeclarativeBase, Session | ||
|
|
||
|
|
||
| class Base(DeclarativeBase): | ||
| pass | ||
|
|
||
|
|
||
| # Use table-shaped class names so synthetic SQL emitted from AST crawl aligns with schema tables. | ||
| class q_users(Base): | ||
| __tablename__ = "q_users" | ||
|
|
||
| id = Column(Integer, primary_key=True) | ||
| email = Column(String(255), nullable=False) | ||
|
|
||
|
|
||
| class q_orders(Base): | ||
| __tablename__ = "q_orders" | ||
|
|
||
| id = Column(Integer, primary_key=True) | ||
| user_id = Column(Integer, nullable=False) | ||
|
|
||
|
|
||
| def orm_unknown_filter_column(session: Session): | ||
| return session.query(q_users.id).filter(text("ghost_col = 1")).limit(1).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| def orm_ambiguous_projection_column(session: Session): | ||
| return ( | ||
| session.query(text("id")) | ||
| .select_from(q_users) | ||
| .join(q_orders, q_users.id == q_orders.user_id) | ||
| .limit(1) | ||
| .all() | ||
|
Comment on lines
+30
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from sqlalchemy import text | ||
| from sqlalchemy.orm import Session | ||
|
|
||
|
|
||
| def raw_unknown_filter_column(session: Session): | ||
| return session.execute(text("SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1")).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| def raw_unknown_table_reference(session: Session): | ||
| return session.execute( | ||
| text( | ||
| "SELECT q_users.id FROM q_users " | ||
| "INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_id LIMIT 1" | ||
| ) | ||
| ).all() | ||
|
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| def raw_ambiguous_unqualified_column(session: Session): | ||
| return session.execute( | ||
| text( | ||
| "SELECT id FROM q_users " | ||
| "INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1" | ||
| ) | ||
| ).all() | ||
|
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| SELECT q_users.id FROM q_users INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_id LIMIT 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| SELECT id FROM q_users INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| CREATE TABLE q_users ( | ||
| id INTEGER PRIMARY KEY, | ||
| email TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE q_orders ( | ||
| id INTEGER PRIMARY KEY, | ||
| user_id INTEGER NOT NULL REFERENCES q_users(id) | ||
| ); | ||
|
|
||
| CREATE TABLE vg110_users ( | ||
| id INTEGER PRIMARY KEY, | ||
| email TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE vg109_orphan ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| id INTEGER PRIMARY KEY | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VG110: model "vg110_users" maps column "id" multiple times (fields "ID" and "LegacyID")