Skip to content

fix(helpers): get_conf drops the default and hides invalid values (return in finally) #387

Backlog

Description

Description

OpenAEVConfigHelper.get_conf returns from inside its finally block (pyoaev/helpers.py#L249-L264):

def get_conf(self, variable, is_number=None, default=None, required=None):
    result = None
    try:
        result = (
            self.__config_obj.get(variable)
            if (self.__config_obj.get(variable) is not None)
            else default
        )
    except ConfigurationError:
        result = default
    finally:
        if result is None and default is None and required:
            raise ValueError(...)
        return result

The return in finally discards any exception that is not a ConfigurationError. For example, Configuration.get raises a ValueError when an is_number value is not a number. When that happens:

  • result is never assigned, so get_conf returns None, even when a default is given;
  • with required=True, it raises Could not find required key ..., although the key is set: its value is just invalid.

The deprecated OpenAEVCollectorHelper and OpenAEVInjectorHelper read their whole configuration through get_conf (collector_log_level, openaev_url, injector_id, ...), and the nuclei and ai-redteam injectors call it directly. An invalid value is silently replaced by None instead of being reported.

Since Python 3.14 (PEP 765), compiling the module also emits SyntaxWarning: 'return' in a 'finally' block in every injector and collector that imports pyoaev.helpers.

The is_number parameter of get_conf is never used.

Environment

  1. OS: macOS (Darwin 27.2), arm64
  2. Version: pyoaev 3.261118.0 (same code on main at 36e8aeb)
  3. Other environment details: same result on Python 3.12, 3.14 and 3.15; the SyntaxWarning appears from Python 3.14

Reproducible steps

  1. Install pyoaev==3.261118.0.
  2. Run:
    import os
    
    from pyoaev.configuration import Configuration
    from pyoaev.helpers import OpenAEVConfigHelper
    
    os.environ["COLLECTOR_PERIOD"] = "60s"  # not a number
    config = Configuration(
        config_hints={"collector_period": {"env": "COLLECTOR_PERIOD", "is_number": True}}
    )
    helper = OpenAEVConfigHelper.from_configuration_object(config)
    
    print(repr(helper.get_conf("collector_period")))
    print(repr(helper.get_conf("collector_period", default=3600)))
    helper.get_conf("collector_period", required=True)

Expected output

The invalid value is reported, for example with the ValueError raised by the conversion (invalid literal for int() with base 10: '60s'). If the error is meant to be swallowed, get_conf(..., default=3600) returns 3600.

Actual output

None
None
ValueError: Could not find required key collector_period with no available default.

On Python 3.14 and later, importing pyoaev.helpers also prints:

pyoaev/helpers.py:264: SyntaxWarning: 'return' in a 'finally' block

Additional information

Proposed fix: move the required check and the return after the try/except block, so other exceptions propagate. Also, either use is_number or drop it.

Activity

  1. added
    bug
    needs triage
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions