Skip to content

fix: disable_auth crash, exception status mapping #280

Closed

Description

@uniqueg

Problem

  • register_openapi (foca/api/register_openapi.py): with disable_auth: true, the loop calls .pop("security", None) on every value of a Path Item, including path-level parameters (a list) and summary/description (strings), and fails with TypeError. The add_operation_fields branch already filters by _OPERATION_OBJECT_FIELDS. The existing tests only check isinstance(res, App), so they do not catch this.
  • foca/errors/exceptions.py: ServiceUnavailable is mapped to status 502. _problem_handler_json looks up type(exception) exactly, so subclasses of mapped exceptions (e.g. class TaskNotFound(NotFound)) return 500. Every handled exception is logged twice (the mapping dict, then the exception).

Proposal

  • Add an _iter_operations(spec) helper that yields only Operation Objects and use it in both branches.
  • Map ServiceUnavailable to 503; resolve the mapping along type(exception).__mro__; log once.
  • The remaining exception refactoring (member filters, framework decoupling) goes to feat: simplify exceptions handling API #240.

Acceptance criteria

  • Test with tests/test_files/openapi_3_petstore_pathitemparam.original.yaml and disable_auth: true: no error, and the spec passed to add_api contains no security/securitySchemes (patch App.add_api and inspect).
  • Tests: ServiceUnavailable returns 503; a subclass of NotFound returns 404; one log record per handled exception.
  • Changelog notes the changed status codes.

Breaking changes

Status codes change for ServiceUnavailable (502 → 503) and for unmapped subclasses of mapped exceptions (500 → parent's status). Downstream custom mappings keep working.

Related

Simp #1, #2; C3 2.2 (MRO lookup); #240

Activity

  1. added
    priority: high
    type: bug
    workload: hours
    on Oct 18, 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

    priority: hightype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions