|
1 | 1 | """Models for Orchestrator Queues API.""" |
2 | 2 |
|
| 3 | +import warnings |
3 | 4 | from datetime import datetime |
4 | 5 | from enum import Enum |
5 | 6 | from typing import Any, Dict, Optional |
6 | 7 |
|
7 | | -from pydantic import BaseModel, ConfigDict, Field, field_serializer |
| 8 | +from pydantic import BaseModel, ConfigDict, Field, field_serializer, model_validator |
8 | 9 | from typing_extensions import Annotated |
9 | 10 |
|
10 | 11 |
|
@@ -42,10 +43,24 @@ def serialize_datetime(self, value): |
42 | 43 | return value.isoformat() if value else None |
43 | 44 | return value |
44 | 45 |
|
45 | | - name: str = Field( |
46 | | - description="The name of the queue into which the item will be added.", |
| 46 | + name: Optional[str] = Field( |
| 47 | + default=None, |
| 48 | + description="Deprecated: use queue_name on the service method instead. The name of the queue into which the item will be added.", |
47 | 49 | alias="Name", |
48 | 50 | ) |
| 51 | + |
| 52 | + @model_validator(mode="before") |
| 53 | + @classmethod |
| 54 | + def warn_name_deprecated(cls, values: Any) -> Any: |
| 55 | + """Emit a deprecation warning when the 'name' field is used directly.""" |
| 56 | + if isinstance(values, dict) and ("name" in values or "Name" in values): |
| 57 | + warnings.warn( |
| 58 | + "The 'name' field on QueueItem is deprecated. Pass queue_name to the service method instead.", |
| 59 | + DeprecationWarning, |
| 60 | + stacklevel=2, |
| 61 | + ) |
| 62 | + return values |
| 63 | + |
49 | 64 | priority: Optional[QueueItemPriority] = Field( |
50 | 65 | default=None, |
51 | 66 | description="Sets the processing importance for a given item.", |
@@ -113,10 +128,24 @@ def serialize_datetime(self, value): |
113 | 128 | return value.isoformat() if value else None |
114 | 129 | return value |
115 | 130 |
|
116 | | - name: str = Field( |
117 | | - description="The name of the queue in which to search for the next item or in which to insert the item before marking it as InProgress and sending it to the robot.", |
| 131 | + name: Optional[str] = Field( |
| 132 | + default=None, |
| 133 | + description="Deprecated: use queue_name on the service method instead. The name of the queue in which to search for the next item or in which to insert the item before marking it as InProgress and sending it to the robot.", |
118 | 134 | alias="Name", |
119 | 135 | ) |
| 136 | + |
| 137 | + @model_validator(mode="before") |
| 138 | + @classmethod |
| 139 | + def warn_name_deprecated(cls, values: Any) -> Any: |
| 140 | + """Emit a deprecation warning when the 'name' field is used directly.""" |
| 141 | + if isinstance(values, dict) and ("name" in values or "Name" in values): |
| 142 | + warnings.warn( |
| 143 | + "The 'name' field on TransactionItem is deprecated. Pass queue_name to the service method instead.", |
| 144 | + DeprecationWarning, |
| 145 | + stacklevel=2, |
| 146 | + ) |
| 147 | + return values |
| 148 | + |
120 | 149 | robot_identifier: Optional[str] = Field( |
121 | 150 | default=None, |
122 | 151 | description="The unique key identifying the robot that sent the request.", |
|
0 commit comments