|
2 | 2 | from enum import Enum
|
3 | 3 | from typing import List, Literal, Union
|
4 | 4 |
|
5 |
| -from pydantic import BaseModel, field_validator |
| 5 | +from pydantic import BaseModel, Field, field_validator |
6 | 6 | from labelbox.schema.labeling_service_status import LabelingServiceStatus
|
7 | 7 | from labelbox.utils import format_iso_datetime
|
| 8 | +from pydantic.config import ConfigDict |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class BaseSearchFilter(BaseModel):
|
11 | 12 | """
|
12 | 13 | Shared code for all search filters
|
13 | 14 | """
|
14 | 15 |
|
15 |
| - class Config: |
16 |
| - use_enum_values = True |
| 16 | + model_config = ConfigDict(use_enum_values=True) |
17 | 17 |
|
18 | 18 | def dict(self, *args, **kwargs):
|
19 | 19 | res = super().dict(*args, **kwargs)
|
20 |
| - if 'operation' in res: |
21 |
| - res['type'] = res.pop('operation') |
22 |
| - |
23 | 20 | # go through all the keys and convert date to string
|
24 | 21 | for key in res:
|
25 | 22 | if isinstance(res[key], datetime.datetime):
|
@@ -216,16 +213,19 @@ class TaskCompletedCountFilter(BaseSearchFilter):
|
216 | 213 | A task maps to a data row. Task completed should map to a data row in a labeling queue DONE
|
217 | 214 | """
|
218 | 215 | operation: Literal[
|
219 |
| - OperationType.TaskCompletedCount] = OperationType.TaskCompletedCount |
| 216 | + OperationType.TaskCompletedCount] = Field(default=OperationType.TaskCompletedCount, serialization_alias='type') |
220 | 217 | value: IntegerValue
|
221 | 218 |
|
222 | 219 |
|
| 220 | + |
| 221 | + |
| 222 | + |
223 | 223 | class TaskRemainingCountFilter(BaseSearchFilter):
|
224 | 224 | """
|
225 | 225 | Filter for remaining tasks count. Reverse of TaskCompletedCountFilter
|
226 | 226 | """
|
227 | 227 | operation: Literal[
|
228 |
| - OperationType.TaskRemainingCount] = OperationType.TaskRemainingCount |
| 228 | + OperationType.TaskRemainingCount] = Field(OperationType.TaskRemainingCount, serialization_alias='type') |
229 | 229 | value: IntegerValue
|
230 | 230 |
|
231 | 231 |
|
@@ -253,5 +253,5 @@ def build_search_filter(filter: List[SearchFilter]):
|
253 | 253 | """
|
254 | 254 | Converts a list of search filters to a graphql string
|
255 | 255 | """
|
256 |
| - filters = [_dict_to_graphql_string(f.dict()) for f in filter] |
| 256 | + filters = [_dict_to_graphql_string(f.model_dump(by_alias=True)) for f in filter] |
257 | 257 | return "[" + ", ".join(filters) + "]"
|
0 commit comments