Skip to content

Commit 988cc8f

Browse files
authored
Merge pull request #110 from code42/bugfix/search-filter-value-field-type
update search filter value field to accept [str] type
2 parents ab63d7f + f3a4b56 commit 988cc8f

5 files changed

Lines changed: 19 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
how a consumer would use the library or CLI tool (e.g. adding unit tests, updating documentation, etc) are not captured
1010
here.
1111

12+
## 1.1.2 - 2023-12-11
13+
14+
### Fixed
15+
16+
- Saved search filter values can now accept a list of strings. Prior to this fix this was incorrectly resulting in a model validation error.
17+
1218
## 1.1.1 - 2023-10-03
1319

1420
### Fixed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ svg = "python docs/example_logging.py"
8585

8686

8787
[[tool.hatch.envs.test.matrix]]
88-
python = ["37", "38", "39", "310","311"]
88+
python = ["37", "38", "39", "310","311", "312"]
8989
[tool.hatch.envs.test]
9090
dependencies = [
9191
"pytest",
@@ -98,6 +98,7 @@ dependencies = [
9898
"python-dateutil",
9999
]
100100
[tool.hatch.envs.test.scripts]
101+
debug = "pytest ./tests/test_file_events.py -s -k saved_search"
101102
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=incydr"
102103
cov-report = "pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=incydr"
103104
no-cov = "cov --no-cov"

src/_incydr_sdk/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: 2022-present Code42 Software <integrations@code42.com>
22
#
33
# SPDX-License-Identifier: MIT
4-
__version__ = "1.1.1"
4+
__version__ = "1.1.2"

src/_incydr_sdk/file_events/models/response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from typing import List
33
from typing import Optional
4+
from typing import Union
45

56
from pydantic import Field
67

@@ -15,7 +16,7 @@ class SearchFilter(ResponseModel):
1516
example="IS_NOT",
1617
)
1718
term: Optional[str] = Field(description="The field to match.", example="user.email")
18-
value: Optional[str] = Field(
19+
value: Optional[Union[List[str], str]] = Field(
1920
None, description="The input for the search.", example="ari@example.com"
2021
)
2122

src/_incydr_sdk/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ class Parent(BaseModel):
174174
for name, field in model.__fields__.items():
175175
# the field.shape tells us if the field contains a single `BaseModel` or something like a `List[BaseModel]`
176176
# we can only traverse singleton models when flattening
177-
if issubclass(field.type_, BaseModel) and field.shape == SHAPE_SINGLETON:
177+
try:
178+
is_subclass = issubclass(field.type_, BaseModel)
179+
# TypeError is thrown if field.type_ is a Union type.
180+
# Assumes our endpoints won't return a field that can be one of multiple models
181+
# This would be a pretty odd API design anyway
182+
except TypeError:
183+
is_subclass = False
184+
if field.shape == SHAPE_SINGLETON and is_subclass:
178185
for child_name in flatten_fields(field.type_):
179186
yield f"{name}.{child_name}"
180187
else:

0 commit comments

Comments
 (0)