JSON schema arrays with uniqueItems=True creates a model using Python sets which are not serializable by default
まだ誰も着手していません。
評価
調査の方向性
生成された AccessControl モデルから始め、Python の JSON シリアライゼーションを通じてモデルが ProgressEvent 内で返される流れを追跡します。示されている uniqueItems スキーマで失敗を再現し、AbstractSet 値を含むモデルを返した場合に、手動で set-to-list 変換を行わなくても正常にシリアライズされることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 107
- フォーク
- 46
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws-cloudformation/cloudformation-cli-python-plugin のほかの issue
-
Support UV オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Repo alive? オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
aws-cloudformation/cloudformation-cli-python-plugin#270 · コメント 1 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
aws-cloudformation/cloudformation-cli-python-plugin#268 · コメント 1 件 · リアクション 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
aws-cloudformation/cloudformation-cli-python-plugin#264 · コメント 1 件 ·
aws-cloudformation/cloudformation-cli-python-plugin の issue をすべて見る
似ている issue
-
bug ci good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 半日 初心者へのやさしさ 62/100
inmanta/inmanta-core#10835 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
sponsored
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100