Skip to content

Validate configuration values with a regex from the modules json - #663

Merged
Martin-Molinero merged 2 commits into
QuantConnect:masterfrom
AlexCatarino:feature-ib-weekly-restart-time-validation
Aug 28, 2026
Merged

Validate configuration values with a regex from the modules json#663
Martin-Molinero merged 2 commits into
QuantConnect:masterfrom
AlexCatarino:feature-ib-weekly-restart-time-validation

Conversation

@AlexCatarino

@AlexCatarino AlexCatarino commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

Interactive Brokers doesn't support weekly restart times later than 23:30 UTC, but --ib-weekly-restart-utc-time accepted any string. An invalid value was only rejected once the deployment reached the brokerage, after the project was compiled and the API call was made.

Instead of hard coding that rule in the CLI, this adds generic regex validation to the modules json configuration schema, so any module can describe the values it accepts:

{
    "id": "ib-weekly-restart-utc-time",
    "type": "input",
    "input-method": "prompt",
    "input-default": "21:00:00",
    "input-regex": "^(?:(?:[01][0-9]|2[0-2]):[0-5][0-9]:[0-5][0-9]|23:(?:[0-2][0-9]:[0-5][0-9]|30:00))$",
    "input-regex-message": "must be a UTC time in hh:mm:ss format, no later than 23:30:00"
}

input-regex is turned into a RegexParameter click type, and input-regex-message describes the accepted values in the error. Both keys are optional, so configurations without them are unaffected, and CLI versions that don't know them ignore them.

It covers the three ways a value reaches the config:

  • the command line option, for every input method, not just prompt
  • the interactive prompt
  • values read from an existing Lean config, which don't go through click, via a new Configuration.validate() called from JsonModule.config_build()

The command line option and the interactive prompt reject the value before the project is compiled. A value read from the Lean config aborts the deployment when running non-interactively, and is prompted for again when running interactively, so the user doesn't have to go and edit lean.json by hand.

$ lean cloud live deploy "My Project" --brokerage "Interactive Brokers" ... --ib-weekly-restart-utc-time 23:50:00
Error: Invalid value for '--ib-weekly-restart-utc-time': '23:50:00' is not supported, it must be a UTC time in hh:mm:ss format, no later than 23:30:00.

The IB constraint itself ships in the modules json, it is not part of this PR. Until the json is republished with input-regex, this PR is a no-op at runtime.

Related Issue

N/A

Motivation and Context

Fail fast and locally with a clear message, instead of after a compile and a round trip, and keep a hand-edited lean.json from carrying an unsupported value into a deployment. Keeping the rule in the modules json means the accepted values stay next to the configuration they belong to, and can be changed without a CLI release.

Requires Documentation Change

No. The option metavar stays TEXT, so the README is unchanged.

How Has This Been Tested?

  • New tests for RegexParameter in tests/test_click.py.
  • New tests/models/test_configuration.py, covering validate(), get_input_type() and the click option type for the different input methods.
  • New tests/models/test_json_module.py, covering config_build() rejecting a value read from the Lean config, prompting for a new one interactively, and accepting any value for a module which doesn't describe a regex.
  • The tests build their configurations from json literals, they don't depend on the modules json served by the CDN.
  • The whole suite passes against the modules json currently served by the CDN, which doesn't describe any regex, so the new keys aren't mandatory.
  • Manually checked with a built wheel and a local modules json carrying the regex: the option, the prompt and the Lean config paths all reject 23:50:00 and 21:00, and lean live deploy --help is unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

🤖 Generated with Claude Code

@AlexCatarino
AlexCatarino force-pushed the feature-ib-weekly-restart-time-validation branch from 390c81a to ac5f578 Compare August 14, 2026 22:52
@AlexCatarino AlexCatarino changed the title Reject IB weekly restart times later than 23:45 UTC Reject IB weekly restart times later than 23:30 UTC Aug 14, 2026
@AlexCatarino
AlexCatarino force-pushed the feature-ib-weekly-restart-time-validation branch 2 times, most recently from 74b4f76 to eefb56b Compare August 26, 2026 22:33
@AlexCatarino AlexCatarino changed the title Reject IB weekly restart times later than 23:30 UTC Validate configuration values with a regex from the modules json Aug 26, 2026
…json

Adds an optional "input-regex" and "input-regex-message" to the module
configurations, so a module describes the values it accepts instead of
the CLI hard coding them.

The regex is checked wherever a value enters the CLI: the command line
options, the interactive prompts and the values read from the Lean
config, which don't go through click and are validated by config_build.
In interactive mode an unsupported value read from the Lean config is
prompted for again, instead of aborting the deployment.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@AlexCatarino
AlexCatarino force-pushed the feature-ib-weekly-restart-time-validation branch from eefb56b to 11b2e0d Compare August 26, 2026 23:00
…acing it

The regex now wraps the type of the input method, so a path is still
converted to a Path, a prompt with an integer input type still converts
to an int and the choices are still checked, with the regex on top.

It is ignored, with a debug message, for the choice and confirm input
methods, whose prompts already describe the values they accept and can
never be satisfied by a regex.

An empty value isn't validated anymore, it means the user didn't provide
one, which config_build reports as a missing option.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G7iy3o91JamKGac8H88FMQ
@Martin-Molinero
Martin-Molinero merged commit 66d650e into QuantConnect:master Aug 28, 2026
38 checks passed
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