Skip to content

fix: reject unknown config keys - #281

Merged
uniqueg merged 2 commits into
devfrom
fix/forbid-unknown-config
Oct 24, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/forbid-unknown-config

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Unknown keys in the custom config are now errors (pre-release review of v0.3.0, finding 9):

  • All models of the custom config inherit ConfigModel with extra="forbid", so misspelled or removed keys in config overlays stop the app and the Celery worker on startup (FOCA raises failed validating custom configuration, chained from the pydantic error that names the key), instead of being ignored. Example: tes.servce_list used to leave the list of backends empty.
  • The unused models Celery and Monitor and the keys custom.celery (not a field, so it was silently dropped) and custom.controllers.celery are removed.
  • The dead custom.controllers.post_task.timeout is replaced by a working timeout in fix: submit tasks to backends exactly once #274 (separate PR), so it still validates here.
  • docs/configuration.md and docs/upgrading.md describe the change.

Verification

  • pre-commit run --all-files (ruff, ruff format, mypy and the other hooks): passed
  • coverage run -m pytest (mongomock): 822 passed, 81 skipped (helm chart tests, helm not installed locally); coverage report: 100%
  • MONGODB_TEST_URI=... pytest against MongoDB 7.0: 822 passed, 81 skipped
  • mkdocs build --strict: passed
  • CI: all checks passed
  • New tests: the base config validates, and unknown keys are rejected at each level of the model (tests/test_config_examples.py). The existing examples of the docs and the chart's values still validate.
  • Reviewer subagents (adversarial, quality): no high or medium findings. The adversarial reviewer checked that all overlays (config.dev.yaml, test and smoke overlays, chart values and CI values, docs examples) validate, that registry data is never passed to the models as a whole, and that the worker refuses to start with an unknown key. The low findings were fixed: full key paths in the upgrade notes, the camelCase storeLogs named in the docstring, and a shared test helper.

Declined review findings

  • Sourcery suggested keeping Celery and Monitor as deprecated aliases for Python importers. Declined: pro_tes.config_models is not a public API, and this is the first release. The config break is documented in docs/upgrading.md (replied in the thread).

Open questions

None.

Closes #276

🤖 Generated with Claude Code

uniqueg and others added 2 commits October 24, 2026 02:19
Forbid extra fields in all models of the custom config (base class
ConfigModel), so that misspelled or removed keys in config overlays
stop the app and the Celery worker on startup instead of being ignored
(e.g., tes.servce_list left the list of backends empty).

Remove the unused models Celery and Monitor and the keys custom.celery
(not a field, silently dropped) and custom.controllers.celery.

Closes #276

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: list the removed keys by full path in the upgrade notes,
name the camelCase storeLogs in the docstring, and reuse the helper
for the base config in the tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR makes custom configuration strict by applying Pydantic extra-field rejection across all models, removes obsolete Celery settings, adds comprehensive validation coverage for base and example configurations, and documents the resulting startup and upgrade behavior.

Sequence diagram for strict custom configuration startup validation

sequenceDiagram
    participant App
    participant Worker as CeleryWorker
    participant Config as CustomConfig
    participant Pydantic

    App->>Config: model_validate(config)
    Config->>Pydantic: validate extra fields
    alt unknown key
        Pydantic-->>Config: ValidationError
        Config-->>App: failed validating custom configuration
        App-->>App: refuse startup
    else valid configuration
        Pydantic-->>Config: validated CustomConfig
        Config-->>App: configuration accepted
    end

    Worker->>Config: model_validate(config)
    Config->>Pydantic: validate extra fields
    alt unknown key
        Pydantic-->>Config: ValidationError
        Config-->>Worker: failed validating custom configuration
        Worker-->>Worker: refuse startup
    else valid configuration
        Pydantic-->>Config: validated CustomConfig
        Config-->>Worker: configuration accepted
    end
Loading

Flow diagram for rejected unknown configuration keys

flowchart TD
    A[Load custom configuration overlay] --> B[Validate with CustomConfig]
    B --> C{Unknown key?}
    C -->|No| D[Start app or Celery worker]
    C -->|Yes| E[Raise Pydantic ValidationError]
    E --> F[Fail custom configuration validation]
    F --> G[Refuse startup]
Loading

File-Level Changes

Change Details Files
Introduce a shared strict-validation base for all custom configuration models.
  • Set Pydantic models to reject unknown fields with extra="forbid".
  • Apply the base model throughout nested custom configuration structures.
  • Keep registry payload handling and existing field validation behavior intact.
pro_tes/config_models.py
Remove obsolete Celery configuration and update the shipped base configuration.
  • Delete unused Celery and Monitor models.
  • Remove custom.celery and custom.controllers.celery settings.
  • Retain validation for the active post-task timeout configuration.
pro_tes/config_models.py
pro_tes/config.yaml
Expand configuration validation tests to cover valid examples and unknown keys at every nesting level.
  • Validate the base custom configuration through the same model used at startup.
  • Reuse a helper for loading base custom settings.
  • Test rejection of misspelled, removed, and nested unknown keys.
tests/test_config_examples.py
Document strict custom-key validation and migration requirements.
  • Explain that application and Celery worker startup fails on unknown keys.
  • List obsolete Celery paths that must be removed from overlays.
  • Clarify the camelCase storeLogs configuration key.
docs/configuration.md
docs/upgrading.md

Assessment against linked issues

Issue Objective Addressed Explanation
#276 Reject unknown or misspelled keys throughout the custom configuration so the app and Celery worker fail at startup. ✅
#276 Remove the obsolete Celery and Monitor models and the ineffective custom.celery and custom.controllers.celery settings, and document the change. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35369686 | 📁 Comparing 99bcb8f against latest (716cbfb)

  🔍 Preview build  

3 files changed
± configuration/index.html
± reference/index.html
± upgrading/index.html

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (716cbfb) to head (99bcb8f).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #281   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         2096      2092    -4     
=========================================
- Hits          2096      2092    -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 24, 2026 01:01

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pro_tes/config_models.py" line_range="153-180" />
<code_context>
         return self


-class Monitor(BaseModel):
-    """Celery monitor settings.
-
-    Args:
-        timeout: Timeout to wait for Celery monitoring.
</code_context>
<issue_to_address>
**Documented Python model imports break**

When a downstream consumer imports either model from `pro_tes.config_models`, `from pro_tes.config_models import Celery, Monitor` raises `ImportError` because both documented model classes are removed; downstream callers that imported them can no longer load.

Retain the symbols as deprecated compatibility aliases or document the Python API break and its replacement.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and an existing overlay with a formerly ignored key, including one of the removed Celery settings, can now prevent the app and worker from starting. Reverting restores startup, but it cannot recover service time already lost.

Blocking findings: pro_tes/config_models.py:180


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pro_tes/config_models.py Resolved
@uniqueg
uniqueg merged commit dcb644c into dev Oct 24, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/forbid-unknown-config branch October 24, 2026 01:21
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.

fix: reject unknown config keys

1 participant