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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- 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
-
area-templates triage:bot-seen triage:needs-human
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/aspire#22356 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Train] An elastic ScalingConfig(num_workers=(0, 0)) is accepted and the run waits forever対応中かも @wguo7 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
ray-project/ray#68217 ·
メンテナーはふだん 2 日以内に返信
-
PairwiseComparisonEvaluator records A when a judge's final verdict is B or C after mentioning [[A]]オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
run-llama/llama_index#24279 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
googleapis/google-cloud-python#19099 ·
メンテナーはふだん 2 日以内に返信
-
area:docs good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100