Skip to content

Commit 5ddd742

Browse files
authored
Fix regression in CodeTF v2 Finding (#1052)
1 parent 981d7cc commit 5ddd742

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/codemodder/codetf/v2/codetf.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from enum import Enum
1212
from typing import TYPE_CHECKING, Optional
1313

14-
from pydantic import BaseModel, model_validator
14+
from pydantic import BaseModel, ConfigDict, model_validator
1515

1616
from codemodder import __version__
1717

@@ -21,9 +21,6 @@
2121
from ..common import Change as CommonChange
2222
from ..common import (
2323
CodeTFWriter,
24-
)
25-
from ..common import Finding as CommonFinding
26-
from ..common import (
2724
Rule,
2825
)
2926

@@ -153,7 +150,12 @@ def validate_description(self):
153150
return self
154151

155152

156-
class Finding(CommonFinding):
153+
class Finding(BaseModel):
154+
id: Optional[str] = None
155+
rule: Rule
156+
157+
model_config = ConfigDict(frozen=True)
158+
157159
def to_unfixed_finding(
158160
self,
159161
*,
@@ -172,7 +174,7 @@ def to_unfixed_finding(
172174
def with_rule(self, name: str, url: Optional[str]) -> Finding:
173175
return Finding(
174176
id=self.id,
175-
rule=Rule(id=self.rule.id, name=name, url=url) if self.rule else None,
177+
rule=Rule(id=self.rule.id, name=name, url=url),
176178
)
177179

178180

tests/test_codetf.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
import requests
77
from pydantic import ValidationError
88

9-
from codemodder.codetf import Change, ChangeSet, CodeTF, DiffSide, Reference, Result
9+
from codemodder.codetf import (
10+
Change,
11+
ChangeSet,
12+
CodeTF,
13+
DiffSide,
14+
Finding,
15+
Reference,
16+
Result,
17+
Rule,
18+
)
19+
from codemodder.codetf.v3.codetf import Finding as FindingV3
1020

1121

1222
@pytest.fixture(autouse=True)
@@ -167,3 +177,12 @@ def test_still_invalidates_bad_value(bad_value):
167177

168178
with pytest.raises(ValidationError):
169179
Change.model_validate(json)
180+
181+
182+
def test_v2_finding_id_optional():
183+
Finding(id=None, rule=Rule(id="foo", name="whatever"))
184+
185+
186+
def test_v3_finding_id_not_optional():
187+
with pytest.raises(ValidationError):
188+
FindingV3(id=None, rule=Rule(id="foo", name="whatever")) # type: ignore[arg-type]

0 commit comments

Comments
 (0)