Code-scanning sweep (#3185)¶
Source: exports of code-scanning/alerts?state=open (36) and
code-quality/findings (52) taken on 2026-11-05, computed at 6acac3325. They
overlap heavily, so the same line often appears in both.
Delivered: the scans of ef8d7f2af closed all 67 fixed items (27 cs, 40 cq), and
what stayed open was only the false positives below, now dismissed. Moving
seed_emission_factors.py had replaced cs 725 with 1362 and cq 258 with 870.
Fixed in code¶
Security
py/stack-trace-exposure(cs 736): the public/health/depsreturnedstr(e)in its body. The error now goes to the log anddetailsis gone from the response, as/readyalready does. Status codes are unchanged, and nothing in this repo or the ops repo readsdetails.js/http-to-file-access(cs 674):gen-api-types.mjsno longer writes the fetched schema to a temp file. It checks the URL answers with JSON and passes the URL toopenapi-typescript. The earlierJSON.parseround-trip did not clear this alert. If the backend dies between the check and the generation, the script now fails instead of falling back to the snapshot.
Dead code and control flow
- Unreachable re-check in
modules/purchase/handlers.py; unusedIT_EMISSION_TYPES. get_role_provider/get_unit_provider:raisemoved after thematch, so no fall-through is reported. Same behaviour.tasks/bootstrap.py:functools.cachereplaces the_BOOTSTRAPPEDglobal. A failed import is still retried on the next call.tasks/runner.pyandscripts/probe_pgbouncer_wait_timeout.py: emptyexceptblocks explain themselves. Comment only.
Protocol stubs
py/ineffectual-statement flags ... bodies, and each code move opened new
alerts. The stubs in schemas/factor.py, schemas/data_entry.py,
workflows/derived_entry_registry.py and modules/equipment/data_entries.py now
have docstring bodies, which the type checker accepts.
Tests
lambda: _FakeSessionCM()becomes_FakeSessionCM.lambda: MagicMock()independency_overridesbecomes a hoisted mock, not a bareMagicMock: FastAPI reads an override's signature, soMagicMock.__init__parameters would become request parameters._ForbiddenSession.__getattr__raisesAttributeError.import+from … importduplicates replaced by stringmonkeypatchtargets.- Explicit
+on the multi-line string intest_db_pool_settings.py; unused import removed fromresults-csv.spec.ts.
Regression test: test_health_deps_response_omits_exception_details in
tests/unit/test_security_alert_fixes.py.
Dismissed¶
These stayed open after the fixes. Rewriting the code to silence them would make
it worse. cs is a code-scanning alert, cq a Code Quality finding.
| Rule | Numbers | Location | Why it is a false positive |
|---|---|---|---|
py/unused-import |
cs 1313, 1314, 725, 1362, 726, 734; cq 347, 348, 870, 232, 239 | test_factor_resolution_indexes.py, seed_emission_factors.py, seed_generic_factors.py, generate_mermaid_erd.py |
Side-effect import: it registers handlers or tables |
py/unused-import |
cq 487, 35 | app/db.py, alembic/env.py |
Side-effect import: Alembic and the metadata need the models registered |
py/ineffectual-statement |
cs 1355; cq 803, 864 | test_sync_pipeline_stream_endpoint_pg.py:534, test_background.py:70 |
await x does have an effect |
py/non-iterable-in-for-loop |
cs 1348; cq 611 | test_join_key_normalization_rules.py:57 |
DataEntryTypeEnum is an Enum, so it is iterable |
py/unused-global-variable |
cs 741; cq 557 | models/module_type.py:74 |
Used at services/simulator_plan_service.py:535 |
py/unused-local-variable |
cq 244 | test_handler_registrations.py:135 |
data_session is passed to the handler later in the test |
py/cyclic-import |
cs 728 | tasks/reference_ingest_tasks.py:14 |
Deliberate lazy-import cycle (Plan 310-C); restructuring it is pipeline work, not cleanup |