Stability and versioning policy#

pytest-queryguard follows Semantic Versioning. This page says what that covers, how deprecations work, and which tests enforce it.

In short: the names in pytest_queryguard.__all__ and pytest_queryguard.app.__all__, the pytest options, flags and markers, the finding kinds, and the files and tools listed below are public; the wording of messages is not. A deprecated name keeps working with a QueryGuardDeprecationWarning for at least two minor releases and three months, and is removed only in a major release. Features marked experimental may change in any minor release. Fixes go into the latest minor release (see Which releases get fixes).

What is public#

The public API is everything below. Changing it incompatibly needs a major release (see "Version numbers"); tests/test_public_api.py fails when it changes by accident.

Files, tools and the action#

Each file has a number for its format. A reader rejects a number it does not know, with an error that says so. New keys may be added in a minor release (read a file by the keys you need and ignore the others); the plugin and its tools read their own files the same way, so a file that a later 1.x release wrote with more keys still reads. A value keeps its type: new data goes into a new key, not into a different shape of an existing one (a per-test value in the budget file stays a number of queries). A new key never narrows what an existing entry matches: a key that would (a baseline entry for one test only, say) changes the identity, so it needs a new format number. Changing the meaning of a key, removing one, or changing what identifies a finding is an incompatible change: the number goes up, and from 1.0 on it needs a major release.

What Format key Public Not public
Baseline file (--queryguard-baseline, see Baseline) "version": 1 findings, each with kind, label, file, function (the identity of a finding; since 1.1.0 the label of a repeated-statement, write-loop or missing-index entry is written and compared without what depends on the database, and a label in the full form still matches, see Baseline) the order of the entries
Budget file (--queryguard-budgets, see Budgets) "format": 1 budgets: test node id to a number of queries the order of the entries
Query counts (--queryguard-json, see CI) "format": 1 the keys documented there: tool, complete, and per test statements, by_verb, db_time, truncated, max_queries_marker, findings (kind, label, count, file, function, line, stack, baselined) tool.version, the text of a finding's message, the order of tests and findings
SARIF file (--queryguard-sarif, see SARIF) SARIF 2.1.0 the rule ids queryguard/<kind>, one per finding kind; the fingerprint key queryguardIdentity/v1 in partialFingerprints and the identity it hashes, so code scanning alerts stay the same alerts after an upgrade; the result properties count, label, tests and peakCount rule names, descriptions and help, message text, primaryLocationLineHash, codeFlows, fixes (experimental, see below)
In-app panel's JSON (<panel_path>/requests.json, see In-application mode) "format": 1 version, watched_engines (the number of watched SQLAlchemy engines), internal_error and requests, each request with the keys of RequestReport.to_dict(): id, name, method, path, route, status, started, duration, statement_count, truncated, db_time, budget, over_budget, error, statements (sql, duration, relationship, file, line, function) and findings (kind, label, file, line, function, count, message) the value of version (the package version), the message text; the panel's own page is served by the same release and does not check format

A new fingerprint key (queryguardIdentity/v2) would close every open alert and open it again, so it is treated as a removal: from 1.0 on, only in a major release.

The command-line tools:

The GitHub Action (action/action.yml, see CI): its inputs with their defaults and accepted values, its outputs (exit-code, sarif-file, json-file), and the name of the artifact it uploads, queryguard-json-<category> (with " : < > | * ? \ / and line breaks of the category turned into -), which later runs of older and newer versions of the action download, and the pull-request comment it updates in place (found by the compare marker above). The action is versioned with the package: pin it to a release tag or a commit. This holds in both places it lives: the vX.Y.Z of MaciejZiel/pytest-queryguard-action is the same action as action/ at this repository's vX.Y.Z. Its major tag (v1) moves only to final releases of that major version, and action/ here keeps working for every 1.x release. The trend input and the trend-report output are experimental, and so are the lint, lint-models and lint-paths inputs and the lint-exit-code output (since 0.10.0). What the job summary and the pull-request comment say is not public.

Names, values and units#

These conventions hold for every public name above, so a new option or field follows them too:

The plugin and the in-application mode share the detection thresholds and their defaults. Two defaults differ on purpose: Settings.max_events is 1000 statements per request (the plugin keeps 10000 per test), because a server keeps the reports of many requests; and the scope is "request" instead of "test".

The in-application mode#

pytest_queryguard.app was experimental from 0.5.0 until it was promoted before 1.0 (#241). Since then it follows the deprecation policy like the rest of the public API. tests/test_public_api.py snapshots its names, signatures, Settings fields and defaults, RequestReport fields and properties, the public fields of Finding and the panel's JSON keys; tests/inapp/test_reporters.py checks the reporters' keys:

What the mode guarantees to the application it runs in, each checked by tests/inapp/ (test_hardening.py above all):

Deprecated names#

Each of these works and emits QueryGuardDeprecationWarning, which names the replacement and the release that removes it:

Deprecated Use instead Since Removed in
ini option queryguard_repeat_scope queryguard_scope 0.8.0 2.0
repeat_scope= of QueryLog.assert_no_nplusone() and app.Settings scope= 0.8.0 2.0
max_queries(n=...) and queryguard_max_queries(n=...) markers a positional limit or limit= 0.8.0 2.0

allow_nplusone is not deprecated: it is a permanent alias of the queryguard_ignore marker.

Exit status#

The plugin does not add exit codes of its own. A test it fails is a failed test (pytest exits with 1), and an invalid option value is a usage error (pytest exits with 4). The compare tool exits with 0, or 2 when a file cannot be read or the arguments are wrong. The experimental trend exits the same way (with --skip-unreadable it leaves out a file it cannot read and exits with 2 only when none could be read). The experimental static check exits with 2 when the --models modules cannot be imported (or define no mapped class), a path does not exist or the arguments are wrong, 1 when it reports a finding and 0 otherwise; a source file it cannot parse is skipped with a message.

What is not public#

Version numbers#

Which releases get fixes#

From 1.0.0 on, bug fixes go into a patch release of the latest minor release (1.Y.Z) and into main. Older minor releases get no backports: a fix reaches you by upgrading to the latest 1.x, which the rules above keep compatible. Security fixes follow the same rule (see the security policy). The 0.x releases get no fixes.

Before 1.0 (history)#

The 0.x releases (0.1.0 to 0.10.0) followed looser rules: a minor release could also contain breaking changes, deprecated first whenever that was possible and always listed under "Changed" or "Removed" in the changelog.

Pre-1.0 clause for new checks. While the version was 0.x, a minor release could change the defaults of newly added detectors: switch a new check on, or let it fail tests by default, instead of introducing it off or as a warning first. Every such change was named in the introduction at the top of the changelog entry and listed first under "Changed", in a "Behavior changes" group, with the option that turns it off. The 0.4.0 changelog entry is an example: the column-load kind is on by default, the index advisor is on whenever the index check is on, and the index check fails tests on SQLite, MySQL and MariaDB. From 1.0 on, the rules above apply strictly: a new check is off or only warns until a later minor release, and a change of default needs a major release.

Deprecation policy#

  1. The old name or behaviour keeps working and starts emitting a QueryGuardDeprecationWarning (a DeprecationWarning subclass, exported from pytest_queryguard) that names the replacement and the release in which it will be removed. It is not a QueryGuardWarning, so a filterwarnings entry that turns findings into errors, or ignores them, does not catch it; pytest shows DeprecationWarning in the warnings summary by default. Command-line flags and ini options print the same warning once per run.
  2. The deprecation is listed under "Deprecated" in the changelog, and the documentation points to the replacement.
  3. It stays for at least two minor releases (one before 1.0) and at least three months after the release that deprecated it, whichever is longer.
  4. It is removed in the next major release (before 1.0 it could be removed in a minor release), listed under "Removed".

A security or data-loss fix may skip these steps; the changelog says so.

A new finding kind, or a stricter version of an existing check, first appears in a release where it can be turned off with an ini option, and the changelog says how. Before 1.0 it could be on by default (see the pre-1.0 clause).

Experimental#

Options, finding kinds, markers, tools and files listed here are public to use but exempt from the deprecation policy: a minor release may change their values, defaults, labels or messages, or remove them, with a changelog entry under "Changed" or "Removed" and no deprecation period. Their ini options and command-line flags are marked EXPERIMENTAL in pytest --help.

tests/django_project/test_public_api.py snapshots the Django surface the same way, so that a change is deliberate: the labels of the findings Django code produces (Book.author, Author.books, Book.body, ...), the loader each fix names (select_related(), prefetch_related(), only()) and the Django versions and databases CI tests, which follow the deprecation policy since 1.1.0; and, for the experimental runner, pytest_queryguard.django.__all__, QueryGuardRunner's --queryguard-mode and its keyword argument, and the keys and defaults of QUERYGUARD (the ini options' names without the prefix). The wording around a fix is not public, as for SQLAlchemy.

The agent skill (skills/pytest-queryguard/SKILL.md), the agent rules in Coding agents and the editor settings in In your editor are documentation, not API: they follow the output they read and may change in any release. The VS Code extension in editors/vscode (see In your editor) has its own version number. It reads the public keys of the JSON and SARIF reports and, for the SQL and the fix in its hover, the text of a finding's message; when that text changes, the hover shows the whole message.

Everything else listed under "What is public" follows the deprecation policy. tests/test_public_api.py still snapshots the experimental ini options and their defaults, so a change to them is deliberate and visible in review.

Failing open#

A bug inside pytest-queryguard must never change the outcome of a test whose result the plugin does not decide, error a test, or end the session with an INTERNALERROR:

tests/test_fault_injection.py makes each of these steps raise in turn and checks the outcome of every test of a small suite.

How this is enforced#

Edit this page on GitHub