JSON schema arrays with uniqueItems=True creates a model using Python sets which are not serializable by default
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với model AccessControl được tạo và lần theo cách một model được trả về trong một ProgressEvent thông qua quá trình tuần tự hóa JSON của Python. Tái hiện lỗi với schema uniqueItems được cung cấp, sau đó xác minh rằng việc trả về một model chứa các giá trị AbstractSet được tuần tự hóa thành công mà không cần chuyển đổi set sang list thủ công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When an definition in the JSON schema is an array with uniqueItems set to True, CFN generates a model with that attribute typed as an AbstractSet (or Python set in real terms) to guarantee that the items are unique. However the JSON module by default does not serialize sets and when the model is returned from the handler it raises an exception when trying to do so.
In order for the model to be returned I need to convert every set to a list in the model so it can be serialized back into JSON.
For example JSON Schema with the following definition:
"AccessControl": {
"type": "object",
"properties": {
"Producers": {
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": { "type": "string" }
},
"Consumers": {
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": { "type": "string" }
}
},
"required": [ "Producers", "Consumers" ],
"additionalProperties": false
}
Generates a model with the following class
@dataclass
class AccessControl(BaseModel):
Producers: Optional[AbstractSet[str]]
Consumers: Optional[AbstractSet[str]]
@classmethod
def _deserialize(
cls: Type["_AccessControl"],
json_data: Optional[Mapping[str, Any]],
) -> Optional["_AccessControl"]:
if not json_data:
return None
return cls(
Producers=set_or_none(json_data.get("Producers")),
Consumers=set_or_none(json_data.get("Consumers")),
)
If the incoming model to the handler is populated and returned in a ProgressEvent the handler fails with an exception trying to serialize a set which it cant do by default. In order to return the model I have to convert every set to a list ie model.AccessControl.Producers = list(model.AccessControl.Producers). This can be tedious if there are multiple exit points in the handler and so should be handled by the model or by adding a set serializer to JSON.
- Ngôn ngữ chính
- Python
- Star
- 107
- Fork
- 46
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws-cloudformation/cloudformation-cli-python-plugin
-
Support UV Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Repo alive? Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
aws-cloudformation/cloudformation-cli-python-plugin#270 · 1 bình luận · 1 reaction ·
-
Improve docstrings for Hooks Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
aws-cloudformation/cloudformation-cli-python-plugin#268 · 1 bình luận · 2 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
aws-cloudformation/cloudformation-cli-python-plugin#264 · 1 bình luận ·
Tất cả issue của aws-cloudformation/cloudformation-cli-python-plugin
Issue tương tự
-
货币战争手改优先级配置缺少列表元素类型校验(P3) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Đang mởarea: ci bug perceived difficulty: 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ClickHouse/clickhouse-connect#1057 ·