Skip to content

fix: handle missing types in CustomVulnerability init#207

Merged
A-Vamshi merged 1 commit intoconfident-ai:mainfrom
frankentini:fix/custom-vulnerability-no-types
Mar 23, 2026
Merged

fix: handle missing types in CustomVulnerability init#207
A-Vamshi merged 1 commit intoconfident-ai:mainfrom
frankentini:fix/custom-vulnerability-no-types

Conversation

@frankentini
Copy link
Contributor

Problem

When CustomVulnerability is initialized without the types parameter (which is Optional[List[str]] and defaults to None), the constructor crashes with an AttributeError because self.types is only set inside the if types: block but is unconditionally accessed in super().__init__(self.types).

# This crashes:
cv = CustomVulnerability(name='Data Leakage', criteria='test')
# AttributeError: 'CustomVulnerability' object has no attribute 'types'

Fix

When types is not provided, default to a single-member enum derived from the vulnerability name. This ensures self.types is always iterable and the vulnerability can be used without explicitly listing types.

Tests

Added test cases for:

  • Initialization without types parameter
  • get_name() works without types
  • Single-type initialization

When CustomVulnerability is created without the types parameter,
self.types was never set before being passed to super().__init__(),
causing an AttributeError. This now defaults to a single type
derived from the vulnerability name.

Added tests for the no-types case and single-type case.
@vercel
Copy link

vercel bot commented Mar 20, 2026

@frankentini is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

@A-Vamshi A-Vamshi merged commit 3d8d166 into confident-ai:main Mar 23, 2026
1 check failed
@A-Vamshi
Copy link
Collaborator

Hey @frankentini, thanks for the PR :)

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