Skip to content

feat: report the boundary check's call rules, E108 to E111 and W103 - #192

Merged
vignzpie merged 6 commits into
release/0.1.0a4from
feat/boundary-calls
Nov 26, 2026
Merged

vignzpie merged 6 commits into
release/0.1.0a4from
feat/boundary-calls

Conversation

@vignzpie

@vignzpie vignzpie commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Task 5 of Roadmap step 7: boundary check #14: neolith._check_calls.findings(source) reports the call rules of ADR 0030 over the source that neolith._check_source reads: neolith.E108 (connect("<id>") outside requires), E109 (an alias of default or of another hosted app, as a literal or DEFAULT_DB_ALIAS, in the five places Decision 5 lists, and the forms that mean default by leaving the alias out), E110 (command_scope for another installed app), E111 (get_model, get_app_config, sender= and get_user_model() naming another installed app; get_model with a literal label of another installed app is E111 whatever its model name, as get_app_config of that label is) and W103 (testing.boot() in a first-party module other than a test module).
  • Every callee is matched by the object its name resolves to, through the names a file binds by top-level imports alone (task 2's bound); a name bound in any other way is a blind spot, never a finding. get_model, get_app_config and sender= are matched on any receiver, a migration's registry parameter included. A label no installed app has is not reported by any E110 or E111 form, get_user_model() included, since Django refuses it at run time.
  • A function of django.db.transaction is judged as the call it makes, also as a bare decorator: @on_commit and the others whose using is not first leave the alias out, and atomic and non_atomic_requests read the decorated function, bare or applied to a lambda, as default. The set holds the functions the installed Django defines, so savepoint_create is judged on 6.1 only. A name in the place of using, a view passed by name to atomic(...) included, is read as a computed alias (Decision 5) and not judged.
  • Each finding is on the line of the value written (alias, identity, label, model), or of the name called, loaded or imported for a form that writes none; a literal spread over lines is on the line it starts on. Not wired into the command yet: task 7 adds it to phase 5.

What changed and why

Files owned (task 5 of #14): new src/neolith/_check_calls.py, new tests/test_check_calls.py, new tests/test_check_aliases.py.
A call spread over lines is placed by its name, not by what a traceback shows, because CPython 3.13 gives the statement's first line for auth\n.get_user_model() (an imported receiver) and the attribute's line for a method call. A W103 in an undeclared app's module names no hosted app (Finding.app is None); 0030's findings sentence does not list that case, which #195 takes to a record.

Links

Part of #14.

Specification and decision records touched

None (implements ADR 0030's rows E108 to E111 and W103; adds no requirement ID).

Spec trace

ID Change Tests
TRN-41 cited (E108) tests/test_check_calls.py::test_connect_with_a_literal_outside_requires_is_e108, ::test_e108_over_a_host
APP-68 cited (E109, E110) every test of tests/test_check_aliases.py; tests/test_check_calls.py::test_command_scope_for_another_installed_app_is_e110, ::test_e110_over_a_host
APP-66 cited (E111) tests/test_check_calls.py::test_get_model_on_any_receiver_naming_another_app_is_e111, ::test_get_app_config_on_any_receiver_naming_another_app_is_e111, ::test_a_sender_named_by_a_string_of_another_app_is_e111, ::test_get_user_model_is_e111_when_auth_user_model_is_another_app_s, ::test_e111_over_a_host_a_migration_s_registry_included

How it was verified

  • E109's oracle is the interpreter: each generated call of each installed transaction function (7 spellings; the alias left out, positional and keyword, 11 alias forms including a lambda; and as a bare decorator on a function, a coroutine and a class) is bound to the real signature, and must be flagged exactly when using binds to None, "default", another hosted app's alias, or a callable for a function with Django's callable(using) branch. Single-condition mutants of each rule's guard, the sender= loop, the uncompilable-module guard and the decorator set each fail a test. CI at f41bf6f: all five jobs green; 11,630 passed and 4 skipped on 3.12 with Django 5.2, 11,631 passed and 3 skipped on 3.15 with Django 6.1, on x86-64 and arm64.
  • Time added (K10), from the log timestamps of CI at ef8ef3d (the rows since add no host): about 1.5 s on 3.15 arm64 (test_check_aliases.py 1.0 s, test_check_calls.py 0.5 s, one child-process host each) and 2.0 s on 3.12 x86-64.
  • Source relied on, Django 5.2.19 / 6.1.3: db/transaction.py signatures 18-129 / 20-140, atomic 316 / 327 and non_atomic_requests 334 / 345 with their callable(using) branch; db/__init__.py:38,43; db/utils.py:13; db/models/query.py QuerySet.using(alias) 1806 / 2019; db/models/manager.py:136 db_manager(using=None, ...); apps/registry.py:188,206 get_model, :150 get_app_config; apps/config.py:224; db/models/signals.py:15-22; db/models/utils.py:5-16; contrib/auth/__init__.py get_user_model 278 / 261. neolith: _host.py:1051 connect(identity, /), :1238 command_scope(app, ...).

Changelog: none (task 7 wires these rules into the command and writes its changelog line).

Checklist

Reviewers look in this order.

  • Decisions and specification (D, P): fits the recorded decisions, or includes a new record. New or changed requirements carry IDs and are listed in the spec trace (P5, P6).
  • Correctness and tests (K, T): behaviour changes ship with tests, and deprecation warnings are errors.
  • Writing and privacy (W, X): one name per concept (W1), and no private references or session trailers (X1).
  • Hygiene (G): branch is <type>/<short-name> (G1), one logical change (G3).

Generated modules for every way of binding each listed callee, judged against the interpreter's own binding of transaction's signatures, and one host in a child process per file.
neolith._check_calls.findings reports E108 (connect() outside requires), E109 (an alias of default or another hosted app, and the bare forms that mean default), E110 (a command scope for another app), E111 (another app's model or config named by a string) and W103 (testing.boot() outside test modules), over the source that neolith._check_source reads. The command wires it in later (task 7 of #14).
@vignzpie vignzpie added this to the 0.1.0a4 milestone Nov 26, 2026
A frozen dataclass in neolith is built once with neolith._frozen.once and has a case in tests/test_frozen.py; App is internal data, like the check's Finding.
A finding is on the line of the value written, or of the name called or
loaded; every function of transaction as a bare decorator and with a lambda
in the place of using is judged against its signature; get_user_model() is
judged by installed labels only; a transaction function the installed Django
lacks is not judged; a sender= after another keyword; and a hosted app's
module that does not compile.
- Each finding is on the line of the value written, or of the name the
  call calls or the expression loads, not where a chained call starts.
- E109's set of transaction functions holds those the installed Django
  defines, so savepoint_create is not judged on 5.2.
- A transaction function used as a bare decorator is judged as the call it
  makes: on_commit and the others that leave using out mean default; atomic
  and non_atomic_requests applied to a lambda mean default as well.
- get_user_model() is E111 only for a label an installed app has, as
  get_model() and the other forms are.

@davinerdo davinerdo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: Changes needed. One spelling of a cross-app model lookup passes E111 while the same lookup through get_app_config fails it.

  1. src/neolith/_check_calls.py:437 (_get_model) and tests/test_check_calls.py:185: apps.get_model("desk", name) gives no E111, only W101, which never fails the check. apps.get_app_config("desk").get_model(name) reaches the same models and is E111. ADR 0030 Decision 5 (line 189) says the check sees "any call of an attribute named get_model with literal arguments that include a label". Its blind-spot example, get_model(label, model), has a computed label. Whatever model a computed model_name picks, a literal label of another installed app already decides that it is that app's model. The test row ("'auth', name", None) pins the lenient reading, so a migration that writes apps.get_model("desk", name) passes as an enforced app. Fix: when the label is a literal and model_name is given but computed, return (label, None) and report E111. Only an empty literal name should stay unjudged. Then change the test row to expect E111. I tried this on a copy (name == "" as the only early return, plus a message for the computed case). Both spellings above then give E111, and 91 of 92 tests pass. The one failure is the expected message of the row you'd change. Description sentence for the second bullet: "get_model with a literal label of another installed app is E111 whatever its model name, as get_app_config of that label is."

Non-blocking:

  1. src/neolith/_check_calls.py:331: transaction.atomic(views.checkout) and non_atomic_requests(view) called on a named function aren't judged, and no W101 is raised either. Only the lambda form is judged. Django's callable(using) branch reads both calls as default, the same as the bare decorator, and wrapping a view in atomic(...) in an app's urls.py is a common idiom. Decision 5's "a computed alias is not reported" covers it on the letter, but the docstring and the description present the bare and lambda forms as the whole set. Either judge a positional argument that is a name the file binds only by a module-level def or class, or say in the module docstring that atomic(<name>) is read as a computed alias.
  2. src/neolith/_check_calls.py:231: the E109 for django.db.connection at its import is placed on the from line. So from django.db import (\n connections,\n connection,\n) reports line 1, while the docstring places a form that writes no alias on "the name it ... loads". ast.alias has carried lineno since 3.10, so the line of the matching alias would follow the rule.
  3. src/neolith/_check_calls.py:189 (_written): changing argument.lineno to argument.end_lineno passes all 92 tests. No test has a literal that spans lines, such as using=("de"\n"fault"). One row with it would pin the placement that ef8ef3d set.

Checked: every Django citation in the description, and each using position and callable(using) branch, on 5.2.19 and 6.1.3. I ran about 300 hand-written forms through judged/findings and found no other gap. A 96-mutant pass on _check_calls.py killed 77; the survivors are equivalent apart from point 4 and untested defensive branches (non-dict DATABASES, non-str AUTH_USER_MODEL). All 455 tests in tests/test_check*.py pass on 5.2.19.

A literal label of another installed app beside a computed model name is
now E111, as get_app_config of that label is. The E109 of an imported
django.db.connection is on the line of the name imported, a literal
spread over lines is pinned to the line it starts on, and a view passed
by name to atomic or non_atomic_requests is documented as a computed
alias.
@vignzpie

Copy link
Copy Markdown
Collaborator Author

Changes in f41bf6f, CI green on all five jobs:

  1. get_model with a literal label and a model name that is computed (positional, model_name=, * or **) now returns (label, None) and is E111 with its own message; only an empty or non-str literal name stays unjudged. The row 'auth', name now expects E111, with rows for the other computed forms and for 'auth.User', name, the own label and an unknown one.
  2. Took the docstring route: a name in the place of using, a view passed by name to atomic/non_atomic_requests included, is stated as a computed alias, and two rows in test_nothing_is_reported_where_no_rule_applies pin it.
  3. The E109 of an imported connection is now on the line of its ast.alias; the parenthesized row expects line 3, plus a row for connection as c.
  4. _SPREAD_VALUES gains a literal spread over lines in each of using=, connections[...], connect, get_model and sender=; the end_lineno mutant now fails.

@vignzpie
vignzpie requested a review from davinerdo November 26, 2026 03:09

@davinerdo davinerdo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: Approve. f41bf6f fixes all four points from my last review, and the description matches the head.

Checked: apps.get_model("desk", name) and its other computed forms (model_name=, *, **, keyword-only) are now E111. An empty, None or non-str literal name, a dotted label with a name, and the own label all stay unjudged. The E109 of an imported connection is on its own line, and so is its as form. Each of these mutants now fails a test: alias.lineno back to node.lineno, argument.lineno to end_lineno, the computed branch returning None, and the empty-name guard dropped. 270 tests in tests/test_check_calls.py, test_check_aliases.py and test_check_source.py pass on Django 5.2.19. One new reading comes from the change I asked for: AppConfig.get_model("<name>", <computed require_ready>) is now E111 when the model name equals another installed app's label. Decision 5's any-receiver rule covers that, and the spelling is rare, so it doesn't block.

@vignzpie
vignzpie merged commit 82f255c into release/0.1.0a4 Nov 26, 2026
5 checks passed
@vignzpie
vignzpie deleted the feat/boundary-calls branch November 26, 2026 03:17
This was referenced Nov 26, 2026
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.

2 participants