Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "archipy",
"source": ".",
"description": "Cursor and Claude Code plugin: rules, skills, agents, and hooks for building apps with ArchiPy",
"version": "0.19.1"
"version": "0.20.0"
}
]
}
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archipy",
"version": "0.19.1",
"version": "0.20.0",
"description": "Cursor and Claude Code plugin: rules, skills, agents, and hooks for building apps with ArchiPy",
"author": {
"name": "SyntaxArc"
Expand Down
2 changes: 1 addition & 1 deletion .cursor-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "archipy",
"source": ".",
"description": "Cursor and Claude Code plugin: rules, skills, agents, and hooks for building apps with ArchiPy",
"version": "0.19.1"
"version": "0.20.0"
}
]
}
2 changes: 1 addition & 1 deletion .cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archipy",
"version": "0.19.1",
"version": "0.20.0",
"description": "Cursor and Claude Code plugin: rules, skills, agents, and hooks for building apps with ArchiPy",
"author": {
"name": "SyntaxArc"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.20.0] - 2026-10-14

### Added

- Partial-index rule: a filter on a column named in a partial index predicate renders its enum values inline with
`literal(..., literal_execute=True)`, since a bound parameter stops matching the index once Postgres switches the
prepared statement to a generic plan; covered in `using-archipy-adapters.mdc` and an `archipy-reviewer` check
reported as **Should fix**

## [0.19.1] - 2026-10-10

### Fixed
Expand Down
11 changes: 11 additions & 0 deletions agents/archipy-reviewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ makes it worse.
- A logic method that reads or writes through a SQLAlchemy-backed repository without an atomic decorator is a finding.
- Sync and async are not mixed within one class or one server.

**Partial indexes** (Postgres)

- A changed query that filters a column named in a partial index predicate (`Index(..., postgresql_where=...)` in the
entity's `__table_args__`, or `CREATE INDEX ... WHERE` in the app's SQL migrations) renders that filter's values
inline with `literal(value, literal_execute=True)`, values from a closed enum only. Bound (`field == value`,
`field.in_(values)`, `_apply_filter`), the filter stops matching the index once Postgres switches the prepared
statement to a generic plan, and the query falls back to a broader index or a full scan (**Should fix**). Columns in
the index key are fine as bound parameters.

**Errors**

- Raise specific ArchiPy `BaseError` subclasses or domain errors, not bare `Exception`.
Expand Down Expand Up @@ -180,6 +189,8 @@ Do not flag these; they are allowed by the rules:
- Local CLI flags in `manage.py` that override `config.FASTAPI` defaults.
- `hashlib` digests for cache keys/ETags (not passwords), and process/task projects calling logics from Behave
steps via `process_logic`.
- `literal(<enum>.value, literal_execute=True)` filters that match a partial index predicate. The values come from a
closed enum and SQLAlchemy quotes them, so this does not break the parameterized-queries rule.
- Style choices the app's own formatter/linter config accepts.

## Report
Expand Down
37 changes: 37 additions & 0 deletions rules/using-archipy-adapters.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,43 @@ except KafkaError as e:

Never leak raw driver exceptions into logics/services.

## Partial Indexes and Bound Parameters

asyncpg runs every query as a server-side prepared statement (psycopg 3 does once a query passes its
`prepare_threshold`). From about the sixth execution on a connection, Postgres may switch that statement to a generic
plan, which sees `$1` instead of the value. A partial index (`CREATE INDEX ... WHERE status = 'PENDING'`) is usable only
when the planner can prove its predicate, so a filter that binds the predicate's column (`field == value`,
`field.in_(values)`, or `SQLAlchemyFilterMixin._apply_filter`) stops matching the index once the plan goes generic. The
query falls back to a broader index or a full scan. Nothing errors, and a small development database rarely shows it.

When a filter targets a column named in a partial index predicate, render its values inline. Do this only for values
from a closed enum; keep user input and IDs bound:

```python
from sqlalchemy import literal

if query_dto.statuses is not None:
query = query.where(
OrderEntity.status.in_(
[literal(status.value, literal_execute=True) for status in query_dto.statuses],
),
)
```

Columns in the index key (`user_id` in `(user_id, created_at) WHERE status = 'PENDING'`) work as bound parameters; only
the predicate's columns need inlining. Each distinct set of inlined values is its own prepared statement, which is
another reason to keep this to small enums.

Confirm the plan with a forced generic plan:

```sql
SET plan_cache_mode = force_generic_plan;
PREPARE q(uuid) AS SELECT count(*) FROM orders WHERE user_id = $1 AND status IN ('PENDING');
EXPLAIN EXECUTE q('00000000-0000-0000-0000-000000000000'); -- should show the partial index
DEALLOCATE q;
RESET plan_cache_mode;
```

## Optional Dependencies

Install the matching ArchiPy extra and import adapter dependencies normally. Do not hide missing extras behind lazy
Expand Down
Loading