Bug: data masking prepare_data leaves dataclasses and Pydantic models unconverted
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
Start with prepare_data in aws_lambda_powertools.utilities.data_masking.base and inspect how _visited is updated during recursive conversion. Run the reproduction in the issue and the existing circular-reference test, then add regression coverage in tests/functional/data_masking/_pydantic/test_data_masking_with_pydantic.py. Done means repeated dataclass and Pydantic instances are converted while circular references remain detected.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Expected Behaviour
DataMasking.erase (and the other operations that go through prepare_data) should convert every dataclass and Pydantic model in the input to plain data, however many there are and whether or not the same instance appears twice.
Current Behaviour
prepare_data records the id() of every object it has visited in _visited to detect circular references, and never removes them. That includes the temporary dicts built by dataclasses.asdict() and model_dump(). Once one of those is freed, CPython reuses its id for a later object, which is then taken for a circular reference and returned unconverted. An instance referenced twice is skipped the same way. erase then fails with TypeError: Object of type X is not JSON serializable.
Code snippet
from dataclasses import dataclass
from pydantic import BaseModel
from aws_lambda_powertools.utilities.data_masking import DataMasking
from aws_lambda_powertools.utilities.data_masking.base import prepare_data
class Card(BaseModel):
number: str
@dataclass
class Item:
card: Card
print(prepare_data({"items": [Item(Card(number=str(i))) for i in range(5)]}))
# some items still contain Card(...) objects instead of dicts
@dataclass
class Person:
age: int
p = Person(age=30)
DataMasking().erase({"items": [p, p]}, fields=["items[*].age"])
# TypeError: Object of type Person is not JSON serializable
Possible Solution
Keep in _visited only the objects on the current conversion path (add before recursing, remove in a finally). Circular references are still caught, and the existing circular-reference test still passes. I have this fix with regression tests in tests/functional/data_masking/_pydantic/test_data_masking_with_pydantic.py (fail on develop, pass with the change) and can open a PR once this is triaged.
Steps to Reproduce
Run the snippet above on develop (5785377).
Powertools for AWS Lambda (Python) version
latest (3.37.0, develop)
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
N/A
- Lingua principale
- Python
- Stelle
- 3.3k
- Fork
- 511
- Merge medio
- 3g 12h
- PR unite (30g)
- 93
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di aws-powertools/powertools-lambda-python
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationForse già presa @lechakrawarthy l’ha presa oggi. Apertabug good first issue help wanted idempotency
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
aws-powertools/powertools-lambda-python#8728 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
bug good first issue help wanted idempotency
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
aws-powertools/powertools-lambda-python#8727 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
bug good first issue help wanted idempotency
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
aws-powertools/powertools-lambda-python#8726 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
bug good first issue help wanted idempotency
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
aws-powertools/powertools-lambda-python#8725 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key valueForse già presa @sumedh-aerram l’ha presa oggi. Apertabug good first issue help wanted idempotency
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
aws-powertools/powertools-lambda-python#8724 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di aws-powertools/powertools-lambda-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
-
[Bug]: Responses API 500s on assistant message with empty content listForse già presa @shadowmodder l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
vllm-project/vllm#64940 ·
I maintainer di solito rispondono entro 1 giorno
-
Limit should define bound_symbolsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertalimits
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
agent-ready area: docs documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Soneso/stellar-agent-wallet#524 ·
I maintainer di solito rispondono entro 1 giorno
-
Keybind quest outdatedApertaStatus: Triage Type: Quest
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
GTNewHorizons/GT-New-Horizons-Modpack#27490 ·
I maintainer di solito rispondono entro 1 giorno